I'm working on a Nuxt.js project and using Vitest for unit testing. I need to verify if the navigateTo function from Nuxt.js is called with a specific path in my tests.
Here's the relevant part of my component (Form.vue), where navigateTo is invoked:
// Form.vue
const onClick = () => {
await navigateTo('/')
}
// Form.test.ts
const navigateToMock = vi.fn()
it('When submit clicked, Then make redirect', async () => {
const wrapper = mount(...)
await wrapper.find("[data-testid='login']").trigger('submit')
await flushPromises()
expect(navigateToMock).toHaveBeenCalledWith('/')
})
I'm struggling to figure out how to spy on or effectively test whether navigateTo was called or not. Does anyone have any suggestions or ideas on how to approach this?
Error: Failed to resolve import "#app" from "components/MyComponent.vue". Does the file exist?
– Arillode