Functions for locating DOM nodes and component instances.
Locate an element inside the component.
selector | String A document.querySelector or jQuery.find() selector. |
options | Object |
options.container | HTMLElement |
options.assert | Boolean If true, the method will throw an error if the node is not valid or could not be found in the DOM. |
Locate an element inside the component.
selector | String A document.querySelector or jQuery.find() selector. |
options | Object |
options.container | HTMLElement The container in which to look for the node. |
Find all DOM nodes that belong to a certain React type within a component.
component | React.Component |
type | React.Class The type of the component you're looking for. |
cond | Function An optional matcher. "). |
Low-level helper for finding a rendered component instance of a certain type, optionally matching some condition on its DOM node.
subject | React.Component The component instance that is expected to contain the target. |
type | React.Class The type of the target. |
cond | Function An optional matcher. ") function. |
React.Component The rendered instance, if found. |
Asserting on an <Icon />
rendered by a <ComboBoxItem />
const Subject = require('../SomeComponentThatRendersComboBoxItems');
const ComboBoxItem = require('components/ComboBoxItem');
const Icon = require('components/Icon');
it('should render a "banana" icon', function() {
const subject = React.render(Subject, document.body);
// We locate the instance we want first
const comboBoxItem = findComponentByType(
subject, ComboBoxItem, ':contains("Option A")'
);
// Then we can find things inside of it:
const iconInsideComboBox = findByType(comboBoxItem, Icon);
// Now, we're assured our assertions are running on the <Icon /> we
// want; no need to use :nth-of-type(), '.combo-box--item .icon', or
// whatever.
assert.equal(iconInsideComboBox.className, 'some-icon');
});
Find all rendered components of a certain type.
component | React.Component |
type | React.Class |
cond | Function An optional matcher. "). |
Deprecated
This interface is part of the legacy API and will be removed in the future. You should instead use scopes for selecting nodes.
node | HTMLElement The DOM node of mounted instance of the component being tested. All exports will be operating on this node and its children. |