Alternative version that worked for me with jest
only:
let assignMock = jest.fn();
delete window.location;
window.location = { assign: assignMock };
afterEach(() => {
assignMock.mockClear();
});
Reference:
https://remarkablemark.org/blog/2018/11/17/mock-window-location/