Closed adragich closed 3 years ago
Hi! Thank you for the detailed report.
Supporting instantiated Vuex stores was introduced last month in https://github.com/testing-library/vue-testing-library/pull/232. Maybe @blimmer can shed some light on how they are avoiding this error? I have never used this option so I haven't encountered it myself.
Hey @adragich and @afontcu!
@adragich is correct that, if you're creating an instantiated store, you'll need to call Vue.use(Vuex)
somewhere in your code. For my purposes, using jest
, I do this once on the global Vue instance in a setupFilesAfterEnv
script.
To make this a bit clearer in the tests, I created #247 which explicitly calls .use()
on the global Vue object, and also adds a code comment about this behavior. I wasn't sure where I'd add to the documentation, but am happy to make updates if either of you has suggestions. My current thought is that the Vuex error message is pretty good at describing what you need to do to resolve the problem.
Fixed in #247. Thank you both!
Vue-testing-library Vuex unit test (src/tests/vuex.js) fails if you change tests order or remove ones with
renderVuexTestComponent
function. It's not a bug of library, but you should refactor your tests as you share these examples in official docs.To Reproduce Steps to reproduce the behavior:
Run test. Move 'can render with an instantiated Vuex store' test to top or remove test cases with
renderVuexTestComponent
function. Test fails.Expected behavior
Test passes.
Related information:
@testing-library/vue
version: 0.0.0-semantically-releasedVue
version: ^2.6.12node
version: v12.13.1npm
(oryarn
) version: yarn@1.22.10Relevant code or config (if any)
Additional context
I think you should discourage using instantiated store or show that initializing vuex on global Vue is okay (vuex does it anyways https://github.com/vuejs/vuex/blob/dev/src/store.js#L542).