-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Vue 3 initial unit test does not work: Property "msg" was accessed during render but is not defined on instance. #5974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@E-jarod moved to the correct repo although this looks more like a question than a bug report. We have a forum and a Discord chat to ask questions! |
vuejs/core@6aa2256 intriduced a change in `DefineComponent` type, that results in a broken bare CLI app that would use VTU, as `mount` will not compile. This relaxes the type definitation by using generic `any`. Fixes vuejs#5974
Stumbled on this as well when upgrading to Vue 3.0.1 and this is indeed reproducible with a bare CLI app. The root cause is Vue 3.0.1 changed the default value of props from The workaround we used to update our applications was to change the default shim to be See #5975 edit: I also opened a repro in vtu-next in case we manage to fix it there vuejs/test-utils#223 |
So, if I understand, it's a problem in the core of Vue ? (not in my code ?) |
@E-jarod it's a problem in your Typescript shim, that was generated by the cli code... just add the line |
@rayfoss Okay and in which fie ? |
Yes its something we need to fix on Vue side (either in vue-next, the CLI or vue-test-utils-next) You can workaround it for now by updating the shim like I did in the PR |
@cexbrayat sorry, I don't get how to modify : - PropsOrPropOptions = any,
- RawBindings = any,
- D = any,
+ PropsOrPropOptions = {},
+ RawBindings = {},
+ D = {},
|
make this your
|
I get the same error ;( |
Try to clear the cash: |
@cexbrayat I still have the same error message |
Okay, I will wait then until the patch 👍 |
I think this only happens when you start the project using
I guess this might be an issue between |
vuejs/core@6aa2256 intriduced a change in `DefineComponent` type, that results in a broken bare CLI app that would use VTU, as `mount` will not compile. This relaxes the type definitation by using generic `any`. Fixes vuejs#5974
I confirm that I have this issue and above proposed fixes also didn't help me. |
vue.global-3.0.11.js
the same error:
|
This is still happening, in another scenario as well. I use Vue 3 with composition API.
I tried multiple arrangements here, like moving the interface into any type argument of that DefineComponent at the bottom, tried any, any, any. Really tried everything I could, restarted lint server every time. This one is a hard one. |
vue3 jest tests throwing the same error except it was my fault as to why. threw me for a loop when I first got started with vue3 and jest mocking. if you so happen to pass in computed properties into the mount option, you have to define all of them otherwise they are set to defineComponent({
name: 'Something',
computed: {
a (): boolean {
return true
},
b (): boolean {
return false
}
}) it('something' () => {
const computed: { a: () => boolean; } = {
a () {
return false
}
}
const wrapper = shallowMount(Something, {computed})
wrapper.vm.b // b is undefined <~ root cause
wrapper.vm.a // false
}) |
Version
3.0.0
Reproduction link
https://github.com/E-jarod/vue3-test.git
Steps to reproduce
Hello, I have simply created a new Vue 3.0.0 (
vue create vue3-test
) project with the following preset :~/.vuerc
I come from angular and I am new to Vue. Everything else works fine, but not the jest unit test.
You can see on my github repo.
What is expected?
The jest test should at least works, because it is the starter project.
What is actually happening?
And when I run :
yarn test:unit # or npm run test:unit
I get the following Error
Can you detail why this is happening ?
The text was updated successfully, but these errors were encountered: