lmiller1990 / vue-testing-handbook

A guide on testing Vue components and applications
https://lmiller1990.github.io/vue-testing-handbook/
876 stars 160 forks source link

Stop the router pollution #147

Closed BaskovicP closed 4 years ago

BaskovicP commented 4 years ago

STEPS TO REPRODUCE You can check the code in the commit.

After some time of wondering why are my wrapper routes not correct it seems that the answer is the automatic hash mode which is activated for creating the vueRouter. (Has to do with the hash mode router getting the jest jsdom window.location and setting the router from this variable) As can be read on https://router.vuejs.org/api/#mode

POSSIBLE PROBLEMS: You may newer be shure on which path you are and if you go with the router on the same path it can produce an error.

Tested on simple vue-cli program.

lmiller1990 commented 4 years ago

I did not realize this subtle bug (I hardly unit test my router, I think that is best done in an integration test using an e2e tool and a real browser).

None the less, this seems important info to include. Thanks for the PR. I can review it this weekend.

PS: does const router = new VueRouter({ routes, mode: 'history' }) work as well? I think history is the most common mode people are using now days.

BaskovicP commented 4 years ago

I agree with you on that one about using the e2e tools. Still much to learn here.

Also checked the 'history' mode now and it seems to work. So the only one that is not working is hash.

Would also be interesting to dig deeper as why. Thanks for the future review.

lmiller1990 commented 4 years ago

Great, I'll merge this up! Thanks for the contribution.