Skip to content
Discussion options

You must be logged in to vote

What do you mean by "not working"? Is all of them still causing Error: useNavigate() may be used only in the context or different errors?
If you only need to mock import { useNavigate } from 'react-router-dom', then technically this should suffice:

vi.mock('react-router-dom', () => ({
    useNavigate: () => vi.fn(),
}));

To keep other exports, you will need importOriginal as shown in https://vitest.dev/api/vi.html#vi-mock

Can you setup a reproduction so we can see the exact setup?

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@swinogrodzki
Comment options

@swinogrodzki
Comment options

@victorz
Comment options

Answer selected by swinogrodzki
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants