--- id: test-utils title: Test Utilities permalink: docs/test-utils.html layout: docs category: Reference --- **Importing** ```javascript import ReactTestUtils from 'react-dom/test-utils'; // ES6 var ReactTestUtils = require('react-dom/test-utils'); // ES5 with npm ``` ## Overview `ReactTestUtils` makes it easy to test React components in the testing framework of your choice. At Facebook we use [Jest](https://facebook.github.io/jest/) for painless JavaScript testing. Learn how to get started with Jest through the Jest website's [React Tutorial](http://facebook.github.io/jest/docs/tutorial-react.html#content). > Note: > > Airbnb has released a testing utility called Enzyme, which makes it easy to assert, manipulate, and traverse your React Components' output. If you're deciding on a unit testing utility to use together with Jest, or any other test runner, it's worth checking out: [http://airbnb.io/enzyme/](http://airbnb.io/enzyme/) - [`Simulate`](#simulate) - [`renderIntoDocument()`](#renderintodocument) - [`mockComponent()`](#mockcomponent) - [`isElement()`](#iselement) - [`isElementOfType()`](#iselementoftype) - [`isDOMComponent()`](#isdomcomponent) - [`isCompositeComponent()`](#iscompositecomponent) - [`isCompositeComponentWithType()`](#iscompositecomponentwithtype) - [`findAllInRenderedTree()`](#findallinrenderedtree) - [`scryRenderedDOMComponentsWithClass()`](#scryrendereddomcomponentswithclass) - [`findRenderedDOMComponentWithClass()`](#findrendereddomcomponentwithclass) - [`scryRenderedDOMComponentsWithTag()`](#scryrendereddomcomponentswithtag) - [`findRenderedDOMComponentWithTag()`](#findrendereddomcomponentwithtag) - [`scryRenderedComponentsWithType()`](#scryrenderedcomponentswithtype) - [`findRenderedComponentWithType()`](#findrenderedcomponentwithtype) ## Reference ## Shallow Rendering > Note: > The shallow renderer has moved to `react-test-renderer/shallow`. [Please see the updated documentation.](/react/docs/shallow-renderer.html) ### `Simulate` ```javascript Simulate.{eventName}( element, [eventData] ) ``` Simulate an event dispatch on a DOM node with optional `eventData` event data. `Simulate` has a method for [every event that React understands](/react/docs/events.html#supported-events). **Clicking an element** ```javascript // const node = this.refs.button; ReactTestUtils.Simulate.click(node); ``` **Changing the value of an input field and then pressing ENTER.** ```javascript // const node = this.refs.input; node.value = 'giraffe'; ReactTestUtils.Simulate.change(node); ReactTestUtils.Simulate.keyDown(node, {key: "Enter", keyCode: 13, which: 13}); ``` > Note > > You will have to provide any event property that you're using in your component (e.g. keyCode, which, etc...) as React is not creating any of these for you. * * * ### `renderIntoDocument()` ```javascript renderIntoDocument(element) ``` Render a React element into a detached DOM node in the document. **This function requires a DOM.** > Note: > > You will need to have `window`, `window.document` and `window.document.createElement` globally available **before** you import `React`. Otherwise React will think it can't access the DOM and methods like `setState` won't work. * * * ### `mockComponent()` ```javascript mockComponent( componentClass, [mockTagName] ) ``` Pass a mocked component module to this method to augment it with useful methods that allow it to be used as a dummy React component. Instead of rendering as usual, the component will become a simple `