Currently, I am implementing unit test for my project and there is a file that contained window.location.href.
window.location.href
I want to mock this to test and here is m
This is valid for Jest + TypeScript + Next.js (in case you use useRoute().push
useRoute().push
const oldWindowLocation = window.location; beforeAll(() => { delete window.location; window.location = { ...oldWindowLocation, assign: jest.fn() }; }); afterAll(() => { window.location = oldWindowLocation; });