Reputation:
I'm trying to mock vue-router's route which I am using in one of my components like route.path . I followed this implementation and the outcome looks like:
vi.mock('vue-router', () => ({
useRoute: vi.fn(() => ({ path: '/signIn' }))
}))
But after running tests I'am getting an error:
TypeError: Cannot read properties of undefined (reading 'path')
Upvotes: 1
Views: 1005
Reputation: 356
useRoute returns a Ref
to the route object. You'd need to change it to something like this:
vi.mock('vue-router', () => ({
useRoute: vi.fn(() => ({ value: { path: '/signIn' } }))
}))
Upvotes: 0