I have a function, that runs on both node and in the browser, which I want to test with jest:
const myFn = () => {
if(typeof window !== 'object'){
return 1;
}
return 2;
}
How am I able to set the global window object to undefined, to test the node branch, and that 1 is returned.
e.g.
test('myTest', ()=> {
global.window = undefined;
expect(myFn()).toEqual(1); // result: 2
});
Ive tried the suggestions here with no success: Mocking globals in Jest