Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enzyme contains example from Enzyme docs does not pass #96

Open
wnayes opened this issue Feb 17, 2020 · 3 comments
Open

Enzyme contains example from Enzyme docs does not pass #96

wnayes opened this issue Feb 17, 2020 · 3 comments

Comments

@wnayes
Copy link
Contributor

wnayes commented Feb 17, 2020

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.

@robertknight
Copy link
Member

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.

@ljharb
Copy link

ljharb commented Feb 17, 2020

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

@mq2thez
Copy link

mq2thez commented Aug 12, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants