|
// Jest 26 with latest JSDOM prevents location from being proxied |
|
// Instead we can redefine location on window, and then restore. |
|
export function mockWindowLocation( |
|
mockLocation: Partial<Location> = { |
|
href: '', |
|
assign: jest.fn(), |
|
reload: jest.fn(), |
|
} |
|
) { |
|
const savedLocation = window.location; |
|
|
|
beforeEach(() => { |
|
Object.defineProperty(window, 'location', { |
|
writable: true, |
|
value: mockLocation, |
|
}); |
|
}); |
|
|
|
afterEach(() => { |
|
window.location = savedLocation; |
|
}); |
|
|
|
return (mockLocation: Partial<Location>) => { |
|
Object.defineProperty(window, 'location', { |
|
writable: true, |
|
value: mockLocation, |
|
}); |
|
}; |
|
} |