0

I am working on a react-native-web application, the application has a logic something like this

return typeof Window !== 'undefined' ? ComponentA : ComponentB

now I am writing the test case for it, I am trying to mock the global.Window I need to mock it to be undefined once and have the Window once.

const originalWindow = {...global.Window};
  it('Should not have Window', () => {
    global.Window = undefined;
    console.log('global.Window: ', global.Window);

  });
  it('Should have window', () => {
     global.window = originalWindow
    console.log('window is present: ', Search);
  });

but in the second testCase the window is still undefined, what is the way around?

fahad991
  • 452
  • 3
  • 8
  • Does this answer your question? https://stackoverflow.com/questions/51425746/jest-js-force-window-to-be-undefined – Lin Du Aug 19 '21 at 03:18
  • The mentioned thread removes the window for the whole testFile, I need to modify the window for Each testCase – fahad991 Aug 19 '21 at 04:47

0 Answers0