Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including react-test-env with all npm packages installed. Try it out:

var reactTestEnv = require("react-test-env")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

react-test-env v0.2.0

React Test Environment Setup

React Test Environment Setup

When React is loaded, it performs a check to detect whether it's executing in the context of a document. Therefore, when testing React components or otherwise simulating a DOM using JSDOM, you must ensure that the document is initialized prior to loading React. The purpose of this module is to reduce this boilerplate and create the expected global variables in a single call.


The module exports a single function which accepts an optional markup string to be passed to JSDOM. You'll likely want to require the module as the first line of your script, so that the globals are available to any subsequent modules that may depend on their existance.

require( 'react-test-env' )();

 * External dependencies
var React = require( 'react' );

// ...

By default, a fully functional localStorage and noop XMLHttpRequest will be added to the global scope. One or both of these can be disabled by passing an additional features option when calling the module.

require( 'react-test-env' )( null, {
    localStorage: false
} );
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free