-
Notifications
You must be signed in to change notification settings - Fork 111
store not available in child components #122
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
After all I've read, could this be due to a clash of Babel versions?
Version |
Can confirm this happening, can't write any tests for components that use vuex. 😞 It's not the babel version. I tried a resolution for it to The store is available deep in the private apis |
Hi! 👋 Just gave the OP repro a go. Not sure why, but removing the first In other words – this works: beforeEach(() => {
actions = {
fetchViewInfo: jest.fn().mockResolvedValue(null),
}
})
it("should render the chart component", async () => {
store = {
actions,
getters: {
viewInfo: () =>
jest.fn().mockReturnValueOnce({
title: "Test Chart",
}),
},
}
const { findByText } = render(GenericView, {
store,
propsData: {
kind: "Dashboard",
},
})
await findByText("Test Chart") // changed Vue.nextTick() + getByText with findByText, but's that unrelated
}) |
@afontcu Like this you basically render the |
Yeah, I guess you're right… I gotta say the component is quite complex and right now I don't have the bandwidth to deep dive on this 😅 It is really weird (and I'd say unlikely?) that the store is not available in child components – I've been testing such scenarios myself, and Vue Testing Lib is only importing Vuex and registering the store as a whole in the Vue instance. If you could come up with a smaller, simpler reproduction case that would mean a lot 🙌 |
@afontcu I updated my repository and tried to simplify the example: https://github.com/mediafreakch/vue-testing-library-bug . It still demonstrates the same problem: The dynamically imported I also wanted to let you know, that I posted the same problem at |
Hi! Thanks for this 🙌 Didn't notice you posted the same issue in Vue Test Utils. That means this is an upstream issue, and as soon as we find a fix in Vue Test Utils, it will work properly here in Vue Testing Lib, too :) I'll go ahead and close this up! |
Describe the bug
store
is undefined in child components.To Reproduce
Steps to reproduce the behavior:
npm install
npm test
The second test fails.
Expected behavior
Second test passes.
Screenshots
Related information:
@testing-library/vue
version: 4.1.0Vue
version: 2.6.11node
version: 12.13.1npm
(oryarn
) version: npm 6.12.1Relevant code or config (if any)
Additional context
Unfortunately the example doesn't run in Codesandbox. There is an issue with they're bundler.
You need to clone the repo and run it locally to reproduce the bug.
I managed to get the same app tested using pure
@vue/test-utils
.I will link the corresponding codesandbox example as soon as I have recovered it. Codesandbox example of@vue/test-utils
The text was updated successfully, but these errors were encountered: