Returns whether or not a patternNode
react element matches any element in the render tree.
Otherwise, the match follows the same rules as matchesElement
.
patternNode
(ReactElement
): The node whose presence you are detecting in the current instance's render tree.Boolean
: whether or not the current wrapper has a node anywhere in its render tree that matches the one passed in.
const wrapper = shallow(( <div> <div data-foo="foo" data-bar="bar">Hello</div> </div> )); expect(wrapper.containsMatchingElement(<div data-foo="foo" data-bar="bar">Hello</div>)).to.equal(true); expect(wrapper.containsMatchingElement(<div data-foo="foo">Hello</div>)).to.equal(true); expect(wrapper.containsMatchingElement(<div data-foo="foo" data-bar="bar" data-baz="baz">Hello</div>)).to.equal(false); expect(wrapper.containsMatchingElement(<div data-foo="foo" data-bar="Hello">Hello</div>)).to.equal(false); expect(wrapper.containsMatchingElement(<div data-foo="foo" data-bar="bar" />)).to.equal(false);
.containsMatchingElement()
expects a ReactElement, not a selector (like many other methods). Make sure that when you are calling it you are calling it with a ReactElement or a JSX expression..containsAllMatchingElements() => ShallowWrapper
- must match all nodes in patternNodes.containsAnyMatchingElements() => ShallowWrapper
- must match at least one in patternNodes
© 2015 Airbnb, Inc.
Licensed under the MIT License.
https://airbnb.io/enzyme/docs/api/ShallowWrapper/containsMatchingElement.html