Closed BeniRupp closed 6 months ago
It looks like flushPromises()
isn't enough. Adding a longer wait await delay(1000)
with a setTimeout, works well. You need a way to await the dynamic import in your test. This is worth asking in Vitest discussions
Hi @posva, thank you for the fast response! π
Damn, I didn't test the behavior with a timeout
. Thanks for the hint! This is,at least, a temporary fix. π
Reproduction
https://github.com/BeniRupp/vue-router-async-import-bug
Steps to reproduce the bug
In a vitest test having a router with two routes, a component with a router-link and dynamic component imports for the route components:
router-link
with vue-test-utils'trigger('click')
fullPath
Expected behavior
The route
fullPath
after clicking therouter-link
is/about
instead of/
.Actual behavior
The route
fullPath
is still/
.Additional information
I assume that the test will finish before the import resolves, because the router changes the route, calls the import function, but the
import()
statement does not resolve (see reproduction repo). Furhtermore, the click on therouter-link
causes a correct routerbeforeEach
event but noafterEach
event.This problem is not reproducible if:
import AboutView from "@/views/AboutView.vue";
instead of the dynamic importrouter.push('/about')
is called instead of clicking the router link