W3cubDocs

/Enzyme

.find(selector) => ReactWrapper

Finds every node in the render tree of the current wrapper that matches the provided selector.

Arguments

  1. selector (EnzymeSelector): The selector to match.

Returns

ReactWrapper: A new wrapper that wraps the found nodes.

Examples

CSS Selectors:

const wrapper = mount(<MyComponent />);
expect(wrapper.find('.foo')).to.have.lengthOf(1);
expect(wrapper.find('.bar')).to.have.lengthOf(3);

// compound selector
expect(wrapper.find('div.some-class')).to.have.lengthOf(3);

// CSS id selector
expect(wrapper.find('#foo')).to.have.lengthOf(1);

// property selector
expect(wrapper.find('[htmlFor="checkbox"]')).to.have.lengthOf(1);

Component Constructors:

import Foo from '../components/Foo';

const wrapper = mount(<MyComponent />);
expect(wrapper.find(Foo)).to.have.lengthOf(1);

Component Display Name:

const wrapper = mount(<MyComponent />);
expect(wrapper.find('Foo')).to.have.lengthOf(1);

Object Property Selector:

const wrapper = mount(<MyComponent />);
expect(wrapper.find({ prop: 'value' })).to.have.lengthOf(1);

© 2015 Airbnb, Inc.
Licensed under the MIT License.
https://airbnb.io/enzyme/docs/api/ReactWrapper/find.html