You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I cannot stub a child component properly, even though I use shallowMount method.
I got an error which has nothing to do with a parent component.
There are two vue components. PhotoModalComponent.vue and LikeComponent.vue.
I am trying to test PhotoModalComponent.vue.
This component has a child component which is LikeComponent.vue.
Therefore, I used shallowMount to stub the child component, because I don't want it to pollute PhotoModalComponent's test.
However, I got an error TypeError: Cannot read properties of undefined (reading 'state') after I execute the test with npm test command.
I see this error as a bug, because state exists only in LikeComponent.vue which is a child component in this case.
Therefore, the child component pollutes parent component`s test for some reason.
I think we have another issue about this, but basically stubs is applied when the component is mounted, and since you are lazily loading the child, it's not available when stubs are applied, thus is it not stubbed.
If you are using Jest, you could just stub the import entirely, I think - that would achieve the same thing.
Subject of the issue
I cannot stub a child component properly, even though I use shallowMount method.
I got an error which has nothing to do with a parent component.
There are two vue components.
PhotoModalComponent.vue
andLikeComponent.vue
.I am trying to test
PhotoModalComponent.vue
.This component has a child component which is
LikeComponent.vue
.Therefore, I used shallowMount to stub the child component, because I don't want it to pollute
PhotoModalComponent
's test.However, I got an error
TypeError: Cannot read properties of undefined (reading 'state')
after I execute the test withnpm test
command.I see this error as a bug, because
state
exists only inLikeComponent.vue
which is a child component in this case.Therefore, the child component pollutes parent component`s test for some reason.
These vue files and a test file are as follows.
PhotoModalComponent.vue
LikeComponent.vue
PhotoModal.spec.js
Expected behaviour
No error.
Actual behaviour
An error occured.
Cannot read properties of undefined (reading 'state')
I have no idea what is going on.
I hope someone can help me to get rid of this error.
Thank you.
The text was updated successfully, but these errors were encountered: