.find(selector) => ReactWrapper
Находит каждый узел в дереве отрисовки текущего обёртки, который соответствует предоставленному селектору.
Аргументы
-
selector(EnzymeSelector): Селектор для сопоставления.
Возвращает
ReactWrapper: Новый обёртки, который оборачивает найденные узлы.
Примеры
Селекторы CSS:
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);
Конструкторы компонентов:
import Foo from '../components/Foo'; const wrapper = mount(<MyComponent />); expect(wrapper.find(Foo)).to.have.lengthOf(1);
Имя отображения компонента:
const wrapper = mount(<MyComponent />);
expect(wrapper.find('Foo')).to.have.lengthOf(1);
Селектор свойства объекта:
const wrapper = mount(<MyComponent />);
expect(wrapper.find({ prop: 'value' })).to.have.lengthOf(1);
Связанные методы
© 2015 Airbnb, Inc.
Licensed under the MIT License.
https://enzymejs.github.io/enzyme/docs/api/ReactWrapper/find.html