shallow.contains requires complete equality, giving this behaviour:
const wrapper = shallow(
<div className="foo">
<span>Hello!</span>
<div className="bar"></div>
</div>
);
wrapper.contains(<div className="foo"><span>Hello!</span><div className="bar"></div></div>) // true
wrapper.contains(<div><span>Hello!</span><div></div></div>) // false
wrapper.contains(<div><span></span><div></div></div>) // false
Having a way to perform looser checks would be good in order to check the structure of the elements without needing to know the classes and other attributes.
However, I would expect it to be false if the node we give to looseContains had attributes that the rendered node does not:
const wrapper = shallow(<div class="foo"></div>);
wrapper.looseContains(<div></div>); // true
wrapper.looseContains(<div class="foo bar"></div>); // false
wrapper.looseContains(<div class="bar"></div>); // false
Are you looking for containsMatchingElement?
That's the one @ljharb! Thanks.
Most helpful comment
Are you looking for
containsMatchingElement?