enzyme-adapter-preact-pure
enzyme-adapter-preact-pure copied to clipboard
Enzyme `contains` example from Enzyme docs does not pass
I've noticed a discrepancy between Enzyme's documentation and the behavior with this adapter. The difference doesn't seem to be explained by the current list of differences.
I'm looking specifically at this API: https://airbnb.io/enzyme/docs/api/ShallowWrapper/contains.html
And these examples:
const wrapper = shallow((
<div>
<div data-foo="foo" data-bar="bar">Hello</div>
</div>
));
expect(wrapper.contains(<div data-foo="foo" data-bar="bar">Hello</div>)).to.equal(true);
expect(wrapper.contains(<div data-foo="foo">Hello</div>)).to.equal(false);
expect(wrapper.contains(<div data-foo="foo" data-bar="bar" data-baz="baz">Hello</div>)).to.equal(false);
expect(wrapper.contains(<div data-foo="foo" data-bar="Hello">Hello</div>)).to.equal(false);
expect(wrapper.contains(<div data-foo="foo" data-bar="bar" />)).to.equal(false);
The last expectation fails when ran with this adapter.
// This one fails:
expect(wrapper.contains(<div data-foo="foo" data-bar="bar" />)).to.equal(false);
I have a code sandbox here that demonstrates the assertion failure: https://codesandbox.io/s/snowy-cache-q6hzg
My suspicion is that it has something to do with handling of the children
prop.
Thanks for the report, this does indeed look like incorrect behavior compared to the docs. It would be useful to confirm that the issue doesn't happen with the React adapter.
A PR to verify that by adding those specific examples to https://github.com/airbnb/enzyme/blob/master/packages/enzyme-test-suite/test/shared/methods/contains.jsx would be happily accepted :-)
Hey, looks like this hasn't gotten any responses in a bit, but I can confirm that in my testing, the React adapter would fail on differences in the children and the Preact adapter does not appear to properly check against the children.