test-utils
test-utils copied to clipboard
mockNuxtImport unable to test for useRouter
I have a router.push in my store, its working completely fine and im able to navigate accordingly
However when i try running test to it using vitest, it shows router not found. from what i see it actually couldnt read the "instance" of my router from my store.
i have this at the top of my file
beforeEach(() => {
setActivePinia(createPinia())
mockNuxtImport('useRouter', () => {
return () => {
return mock<Router>()
}
})
})
and then
it('will navigate user to Route.dashboard upon logging in', async () => {
const authStore = useAuthStore()
const router = useRouter()
expect(router.push).not.toHaveBeenCalled()
await authStore.login({
username: emailUsername,
password,
})
expect(router.push).toHaveBeenCalledOnce() // !! HERE is not found. any idea what might be the issue
})