test-utils
test-utils copied to clipboard
Bug: Testing component with onBeforeRouteLeave hook raising "No active route record was found" warning
Describe the bug
Whenever i want to test component, which is using onBeforeRouteLeave (or onBeforeRouteUpdate) - i'm getting a warning:
[Vue Router warn]: No active route record was found when calling `onBeforeRouteLeave()`. Make sure you call this function inside of a component child of <router-view>. Maybe you called it inside of App.vue?
That happen when we want to use real router - issue do not exists while using mocked router.
To Reproduce https://stackblitz.com/edit/github-docpnd?file=src%2Fmain.ts
In provided example above - there is simple test, route configuration and two components.
TestComponent is simple component, which is rendered under Stepper component.
Whenever we mount in tests component, which is using onBeforeRouteLeave - warning is raised.
Expected behavior No warning is raised.
Related information:
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
npmPackages:
@vue/test-utils: ^2.3.2 => 2.3.2
vitest: ^0.31.0 => 0.31.4
vue: ^3.3.2 => 3.3.4
Additional context
- I can see that mocking router works
Thank you!