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

contains does not fail on string input #145

Closed
IanVS opened this issue Jan 28, 2016 · 5 comments
Closed

contains does not fail on string input #145

IanVS opened this issue Jan 28, 2016 · 5 comments

Comments

@IanVS
Copy link

IanVS commented Jan 28, 2016

The API for contains() clearly indicates that it should be provided a node, and yet if a string is provided instead, it seems that it will return true, no matter the string. I would have expected an error to be thrown, or at least that false would be returned.

@lelandrichardson
Copy link
Collaborator

hmm. I'd expect the following behavior:

shallow(<div>foo</div>).contains('foo'); //=> true
shallow(<div>foo</div>).contains('bar'); //=> false

and I assume that you're saying the second statement returns true as well, right?

smacker added a commit to smacker/enzyme that referenced this issue Jan 29, 2016
lelandrichardson added a commit that referenced this issue Feb 1, 2016
fix #145 `contains` does not fail on string input
@IanVS
Copy link
Author

IanVS commented Feb 1, 2016

Thanks @smacker! Perhaps the API docs should be updated as well?

@smacker
Copy link
Contributor

smacker commented Feb 2, 2016

I'm not sure that we need to update docs. It's expected behavior.

@IanVS
Copy link
Author

IanVS commented Feb 2, 2016

Hm, maybe I misunderstand the docs then. The signature is: .contains(nodeOrNodes) => Boolean and at the bottom is:

.contains() expects a ReactElement, not a selector (like many other methods). Make sure that when you are calling it you are calling it with a ReactElement or a JSX expression.

But, "foo" in @lelandrichardson's example above isn't a ReactElement or a JSX expression, and yet the assertion will be true. I admittedly don't understand all this very well, am I missing something?

@smacker
Copy link
Contributor

smacker commented Feb 2, 2016

Strings and numbesr are "nodes". Also it's valid JSX expression. But of course let maintainers decide.

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

No branches or pull requests

4 participants