I have a function that works on both node and browser, which I want to test with a joke:
const myFn = () => { if(typeof window !== 'object'){ return 1; } return 2; }
How can I set the global window object to undefined in order to check the node branch and return this value.
eg.
test('myTest', ()=> { global.window = undefined; expect(myFn()).toEqual(1); // result: 2 });
Ive tried the suggestions here without success: Mocking Globals at Jest
source share