Skip to content

Instantly share code, notes, and snippets.

@danielrohers
Last active February 1, 2021 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielrohers/0678081b62a9b8d4ee73a5504a4afdb5 to your computer and use it in GitHub Desktop.
Save danielrohers/0678081b62a9b8d4ee73a5504a4afdb5 to your computer and use it in GitHub Desktop.
window.location.reload jest mock
// tests/__mocks__/browserMocks.js
Object.defineProperty(window, 'location', {
value: {
...window.location,
reload: jest.fn()
}
});
// Example of use:
expect(window.location.reload).toHaveBeenCalled();
expect(window.location.reload).not.toHaveBeenCalled();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment