How can I reuse a mock of a module from node_module ? #5316
-
I have the following code (it's working fine): import {render} from '@testing-library/react'
import {vi} from 'vitest'
import LoginPage from 'LoginPage.jsx'
const mockUseNavigate = vi.fn()
vi.mock('react-router-dom', async () => {
const actual = await vi.importActual('react-router-dom')
return {
...actual,
useNavigate: () => mockUseNavigate
}
})
it('should redirect to the home page', () => {
render(<LoginPage/>)
expect(mockUseNavigate).toHaveBeenCalledWith('/home')
}) However, I have other tests that I need How can I do that? Thank you! |
Beta Was this translation helpful? Give feedback.
Answered by
sheremet-va
Feb 29, 2024
Replies: 1 comment 3 replies
-
You can put the mock statement in a file and make sure to always import it first before other imports |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
robbporto
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can put the mock statement in a file and make sure to always import it first before other imports