ReactTestUtils
//importing
import ReactTestUtils from 'react-dom/test-utils'; // ES6
var ReactTestUtils = require('react-dom/test-utils'); // ES5
Makes it easy to test React components in the testing framework of your choice.
Simulate
Simulate an event dispatch on a DOM node with optional eventData event data.
Simulate has a method for every event that React understands.
renderIntoDocument()
mockComponent()
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 <div> (or other tag if mockTagName is provided) containing any provided children.
isElement()
isElementOfType()
isDOMComponent()
isCompositeComponent()
findAllInRenderedTree()
Traverse all components in tree and accumulate all components where test(component) is true.
This is not that useful on its own, but it’s used as a primitive for other test utils.
scryRenderedDOMComponentsWithClass()
Finds all DOM elements of components in the rendered tree that are DOM components with the class name matching className.
findRenderedDOMComponentWithClass()
Like scryRenderedDOMComponentsWithClass() but expects there to be one result, and returns that one result, or throws exception if there is any other number of matches besides one.
scryRenderedDOMComponentsWithTag()
Finds all DOM elements of components in the rendered tree that are DOM components with the tag name matching tagName.
findRenderedDOMComponentWithTag()
Like scryRenderedDOMComponentsWithTag() but expects there to be one result, and returns that one result, or throws exception if there is any other number of matches besides one.
scryRenderedComponentsWithType()
findRenderedComponentWithType()
Related concepts
- ReactTestUtils: Simulate
- ReactTestUtils: renderIntoDocument()
- ReactTestUtils: mockComponent()
- ReactTestUtils: isElement()
- ReactTestUtils: isElementOfType()
- ReactTestUtils: isDOMComponent()
- ReactTestUtils: isCompositeComponent()
- ReactTestUtils: findAllInRenderedTree()
- ReactTestUtils: scryRenderedDOMComponentsWithClass()
- ReactTestUtils: findRenderedDOMComponentWithClass()
- ReactTestUtils: scryRenderedDOMComponentsWithTag()
- ReactTestUtils: findRenderedDOMComponentWithTag()
- ReactTestUtils: scryRenderedComponentsWithType()
- ReactTestUtils: findRenderedComponentWithType()
- Shallow Rendering