1

I have the following in the tests of a React component using chai-enzyme:

const wrapper = mount(<Something />)
expect(wrapper).to.contain(<SomethingElse />) //works
expect(wrapper).to.containMatchingElement(<SomethingElse />) //does not work

and wonder why contain works but containMatchingElement does not.

Treefish Zhang
  • 1,131
  • 1
  • 15
  • 27
  • Refer the documentation and example here: https://github.com/producthunt/chai-enzyme. – arpitjain2402 Oct 10 '17 at 15:50
  • @arpitjain: I had included the same link as yours. However, I can not figure out my problem. Would you enlighten me? – Treefish Zhang Oct 10 '17 at 17:55
  • Sure. To keep it simple let's take an example of an array x= [1,2,3,4,5]. In contain: If you assert that x must contain all the elements i.e 1,2,3,4,5 this will return you true and if you assertion on subset of x then it will return you false. where as in containMatchingElement you can assert on subset of x. Hope it helpe! – arpitjain2402 Oct 10 '17 at 18:05
  • I have trouble connecting what you said with the difference between `expect(wrapper).to.containMatchingElement()` vs `expect(wrapper).to.contain()` on that link. If `containMatchingElement` can match nodes meeting part of the props and `contain` matches nodes meeting all props , then won't it go that anything passes `contain` will automatically pass `containMatchingElement`? – Treefish Zhang Oct 10 '17 at 18:48

0 Answers0