Reactjs: document is not defined

Ensure you add this code documentation block at the top of the your test file

/**
 * @jest-environment jsdom
 */

if you're rendering this server side, there will be no "document" object. try wrapping it in the following:

if (typeof window !== 'undefined') {
    React.render(<MainWrapper />, document.getElementById("root"));
}

this will check to see if a window object is present - meaning its in the browser - which also means that the document object is present


to keep this answer valid

Newer versions of React have been split into multiple packages, you will need to import from react-dom now:

import ReactDOM from 'react-dom';

if (typeof window !== 'undefined') {
    ReactDOM.render(<MainWrapper />, document.getElementById("root"));
}