-
Notifications
You must be signed in to change notification settings - Fork 668
vue-router is shared between tests #1681
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 would say this is not a vue-test-utils thing to worry about. You may want to try |
Each test should have it's own instance of Vue Router using this strategy. If you do |
Yes, If I replace |
Ok I remember this now. Turns out I actually found a solution for this. I wrote about it in my handbook. You need to pass const localVue = createLocalVue()
localVue.use(VueRouter)
const router = new VueRouter({routes, mode: 'abstract' }) I don't think this is something VTU will be doing automatically. I'd say the only solution is to document this better. This should solve your problem! Let me know if it doesn't. |
@lmiller1990 Additionally, the handbook contains wrong information: For 'history' mode it is not working. You can check this on my repro project. |
I will make a PR to my book to fix that typo - it should be I am not 100% sure why history has this issue. My guess is that the url is changed in one test, and resetting the url is outside the scope and control of Vue Test Utils, so even if you make a new router it will automatically grab the url from the current location, which is effectively a global variable that has been mutated. I could be completely off. I would need to look into Vue Router in more depth to give you a definite answer, I do not have the time to do this right now though. If you figure it out please let me know and submit a PR to the handbook with more info. |
@lmiller1990 In the In the And of course However, in the This is why only the |
I was kind of correct then! I'll add that information to my book. Thanks @Mikilll94. |
Ran into this problem just now and in addition to using return render({ component: SomeComponent, router: buildRouter() })
// ...
const buildRouter = () => {
return new VueRouter({
mode: 'abstract',
routes,
})
} |
I wrote a bit about this in a little book I'm writing (freely available): https://cypress-testing-handbook.netlify.app/vue-router.html |
Subject of the issue
I have the following test:
If you run it, you will see that it prints this to the console:
This means that the router instance is shared between tests, even though I am using separate
localVue
androuter
for both tests.IMO tests should be independent -> they should have their own instance of vue-router. Is it possible with library? If you follow the examples in the docs, then you will end up with shared vue-router instance between tests.
Steps to reproduce
Just run unit tests in this project (
npm run test:unit
)testing-vue-router.zip
Expected behaviour
All tests should have their own instance of vue-router
Actual behaviour
vue-router instance is shared between tests
The text was updated successfully, but these errors were encountered: