ReactTestUtils
Type members
Types
Value members
Concrete methods
When writing UI tests, tasks like rendering, user events, or data fetching can be considered as "units" of interaction with a user interface. React provides a helper called act() that makes sure all updates related to these "units" have been processed and applied to the DOM before you make any assertions:
When writing UI tests, tasks like rendering, user events, or data fetching can be considered as "units" of interaction with a user interface. React provides a helper called act() that makes sure all updates related to these "units" have been processed and applied to the DOM before you make any assertions:
act {
// render components
}
// make assertions
This helps make your tests run closer to what real users would experience when using your application.
When writing UI tests, tasks like rendering, user events, or data fetching can be considered as "units" of interaction with a user interface. React provides a helper called act() that makes sure all updates related to these "units" have been processed and applied to the DOM before you make any assertions:
When writing UI tests, tasks like rendering, user events, or data fetching can be considered as "units" of interaction with a user interface. React provides a helper called act() that makes sure all updates related to these "units" have been processed and applied to the DOM before you make any assertions:
await act(async () => {
// render components
});
// make assertions
This helps make your tests run closer to what real users would experience when using your application.
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.
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.
Same as scryRenderedComponentsWithType 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.
Same as scryRenderedComponentsWithType 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.
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.
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.
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.
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.
Turn <div data-reactroot="">hello</div>
into <div>hello</div>
Turn <div data-reactroot="">hello</div>
into <div>hello</div>
Renders a component into the document body via ReactDOM.render().
Renders a component into the document body via ReactDOM.render().
Unlike ReactTestUtils.renderIntoDocument, this allows DOM focus to work.
Render a component into a detached DOM node in the document. This function requires a DOM.
Render a component into a detached DOM node in the document. This function requires a DOM.
Finds all instances of components with type equal to componentClass.
Finds all instances of components with type equal to componentClass.
Finds all instance of components in the rendered tree that are DOM components with the class name matching className.
Finds all instance of components in the rendered tree that are DOM components with the class name matching className.
Finds all instance of components in the rendered tree that are DOM components with the tag name matching tagName.
Finds all instance of components in the rendered tree that are DOM components with the tag name matching tagName.
Renders a component then unmounts and cleans up after use.
Renders a component then unmounts and cleans up after use.
- Value Params
- intoBody
Whether to use renderIntoBody or ReactTestUtils.renderIntoDocument.
Renders a component then unmounts and cleans up after use.
Renders a component then unmounts and cleans up after use.
- Value Params
- intoBody
Whether to use renderIntoBodyAsync() or renderIntoDocumentAsync().
Renders a component then unmounts and cleans up after use.
Renders a component then unmounts and cleans up after use.
- Value Params
- intoBody
Whether to use renderIntoBodyFuture() or renderIntoDocumentFuture().
Renders a component into the document body via ReactDOM.render(), then unmounts and cleans up after use.
Renders a component into the document body via ReactDOM.render(), then unmounts and cleans up after use.
Unlike ReactTestUtils.renderIntoDocument, this allows DOM focus to work.
Renders a component into the document body via ReactDOM.render(), and asynchronously waits for the Async to complete before unmounting.
Renders a component into the document body via ReactDOM.render(), and asynchronously waits for the Async to complete before unmounting.
Renders a component into the document body via ReactDOM.render(), and asynchronously waits for the Future to complete before unmounting.
Renders a component into the document body via ReactDOM.render(), and asynchronously waits for the Future to complete before unmounting.
Renders a component into detached DOM via ReactTestUtils.renderIntoDocument, then unmounts and cleans up after use.
Renders a component into detached DOM via ReactTestUtils.renderIntoDocument, then unmounts and cleans up after use.
Renders a component into the document body via ReactDOM.render(), and asynchronously waits for the Async to complete before unmounting.
Renders a component into the document body via ReactDOM.render(), and asynchronously waits for the Async to complete before unmounting.
Renders a component into detached DOM via ReactTestUtils.renderIntoDocument, and asynchronously waits for the Future to complete before unmounting.
Renders a component into detached DOM via ReactTestUtils.renderIntoDocument, and asynchronously waits for the Future to complete before unmounting.
Deprecated methods
- Deprecated
Implicits
Inherited implicits
- Inherited from
- ReactTestUtilExtensions
- Inherited from
- ReactTestUtilExtensions1