enzyme-adapter-preact-pure icon indicating copy to clipboard operation
enzyme-adapter-preact-pure copied to clipboard

Enzyme `contains` example from Enzyme docs does not pass

Open wnayes opened this issue 5 years ago • 3 comments

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.

wnayes avatar Feb 17 '20 15:02 wnayes

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.

robertknight avatar Feb 17 '20 17:02 robertknight

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 :-)

ljharb avatar Feb 17 '20 17:02 ljharb

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.

mq2thez avatar Aug 12 '20 19:08 mq2thez