Hey,
I am testing routing on a component (composition API) which uses an onBeforeRouteUpdate navigation guard.
When I initialize the router mock like this:
the breakpoint in the guard never hits.
I need to test behavior of the guard depending on the :idparam, and from my understanding the param will not be recognized if the routes array is empty. When I check router.currentRoute in the second example, I can see that the second route is correctly loaded with the expected :id param.
Am I doing something wrong? Or is there another way to test the in-component guard behavior with vue 3 / composition API?
Before route update implies a route that updates rather than a new route (you have two routes in your array). You can find more about this in vue router docs, navigation guards
Hey, I am testing routing on a component (composition API) which uses an
onBeforeRouteUpdate
navigation guard. When I initialize the router mock like this:and run a test like this:
I can see a breakpoint in my
onBeforeRouteUpdate
being hit as expected.But if I initialize the mock with routes:
the breakpoint in the guard never hits. I need to test behavior of the guard depending on the
:id
param, and from my understanding the param will not be recognized if the routes array is empty. When I checkrouter.currentRoute
in the second example, I can see that the second route is correctly loaded with the expected:id
param.Am I doing something wrong? Or is there another way to test the in-component guard behavior with vue 3 / composition API?
Thank you in advance.
Versions: vitest: 0.33.0 vue: 3.3.4 vue-router-mock: 1.0.0