Categories
React Answers

How to fix window is not being exposed to Jest?

Spread the love

To fix window is not being exposed to Jest, we create the window object with jsdom.DOM().

For instance, we write

global.window = new jsdom.JSDOM().window;
global.document = window.document;

to create the window object with jsdom.JSDOM().window.

Then we get the document object with window.document.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *