You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Heya! 👋
While I was waiting for the 3.6.x release, I rolled some in-house vue-router hooks as per #3760 (comment). This allowed refactoring some options-API components to composition-api "mode" while keeping my test suite intact.
I thought the refactor to use the official package hooks would be a simple find/replace but my test suite broke. After some digging, the reason is that the hooks implementation relies on router.currentRoute property and afterEach hook, which made the tests using the simplest $route mock as suggested in vue-test-utils docs to fail.
Hello, thank you for taking time filling this issue!
However, we kindly ask you to use our Issue Helper when creating new issues, in order to ensure every issue provides the necessary information for us to investigate. This explains why your issue has been automatically closed by me (your robot friend!).
I hope to see your helper-created issue very soon!
Heya! 👋
While I was waiting for the
3.6.x
release, I rolled some in-house vue-router hooks as per #3760 (comment). This allowed refactoring some options-API components to composition-api "mode" while keeping my test suite intact.I thought the refactor to use the official package hooks would be a simple find/replace but my test suite broke. After some digging, the reason is that the hooks implementation relies on
router.currentRoute
property andafterEach
hook, which made the tests using the simplest $route mock as suggested in vue-test-utils docs to fail.vue-router/src/composables/globals.js
Lines 23 to 30 in e3273b3
Steps
<!-- using composition API --> <template> <div>{{ msg }}</div> </template> <script> import { useRoute } from 'vue-router/composables'; import { computed } from 'vue'; export default { computed: { msg() { return `My route name is ${this.$route.name}`; } } }; </script>
<!-- Refactoring using composition-api --> <script> import { useRoute } from 'vue-router/composables'; import { computed } from 'vue'; export default { setup() { const $route = useRoute(); const msg = computed(() => { `My route name is ${$route.name}`; }); return { msg, }; }, }; </script>
One of The Fixes
...or setting up a router with localVue as per docs... or stubbing modules
jest.mock()
.Expectations
Reproducing Demos
Question
If you've went this way, I'm sure there are good reasons for it. But curious on why didn't you gt with a similar approach as vue-router@4, as in, with a reactive object derived from
getCurrentInstance().proxy.$route
as per f1eb2b1#diff-2042e0452c0d0edd730403740acc8d4337382101087ad62a677e1e2fdae05e8fR8-R17 which kept tests working without any change — but surely break some other stuff.Cheers and thanks for your work on the router! Feel free to close this if you think it's related with
@vue/test-utils
docs instead ✌️The text was updated successfully, but these errors were encountered: