-
Notifications
You must be signed in to change notification settings - Fork 668
Child component using Vue.extends not receiving global $state property from Vuex #382
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
I think this is happening because the constructor of the child component is not extending from the |
As you said, the problem is that you're creating the component with Vue.extend. There are a few options I can think of to fix this. First, we could fix the mount(Component, {
subComponent: localVue.extend(subComponent)
}) Second, we could call Third, we could add an option that would call |
I'm calling I don't think the first option, of leaving it the user to call |
Great to see you, Edd in VueConf.US 😄 I agree with Edd's third option if the second option is too much for non- mount(Component, {
localVue,
extendChildren: true
}) Ideally, don't want to have the weird option. I wonder if we could detect whether |
I am also having troubles with this. LocalVue does not seem capable of passing the $store down to subcomponents. Shallow works fine. I guess I will just stick to doing tests with shallow rendering for now. |
We now extend all extended child components automatically |
That's awesome, thanks for working on that, Edd! |
I think I do observe exactly the problem mentioned in this issue with Async Recursive Components in a Webpack environment... An abstract of the setup:
When testing My workaround for now is to stub the UPDATE: |
Version
1.0.0-beta.10
Reproduction link
https://jsfiddle.net/7t28dy1u/
Steps to reproduce
Run the fiddle - console error because
this.$store
is undefined on the child component.What is expected?
All child components should receive the global
$store
mixin from Vuex.What is actually happening?
Only the root element is receiving the
$store
property.I can fix the jsbin by removing the
Vue.extend
notation and just passing the raw javascript objects into mount. I also confirmed that this works as expected when using Vue to construct the component normally (not using vue-test-utils).I ran into this because I was using ES6 imports to import my store into all my app components. I switched to using
this.$store
which works fine in the app, but broke a lot of my unit tests that were using vue-test-utils to mount the components.The text was updated successfully, but these errors were encountered: