Is there any way in Jest to mock global objects, such as navigator, or Image*? I\'ve pretty much given up on this, and left it up to a series of mo
navigator
Image
The correct way of doing this is to use spyOn. The other answers here, even though they work, don't consider cleanup and pollute the global scope.
// beforeAll jest .spyOn(window, 'navigator', 'get') .mockImplementation(() => { ... }) // afterAll jest.restoreAllMocks();