The example code for present() is misleading
See original GitHub issue.find()
returns ShallowWrapper
which is alway present no matter what. – http://airbnb.io/enzyme/docs/api/ShallowWrapper/find.html
expect(wrapper.find('.foo')).to.exist; // passes
expect(wrapper.find('.foo')).to.present(); // passes
Instead existence check should look like
expect(wrapper.find('.foo').length).to.equal(1); // fails
expect(wrapper.find('.foo').html()).to.exist; // fails
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Check Visibility of Web Elements Using Various Types ...
WebDriver Code; isDispalyed(); isEnabled(); isSelected() ... specified web element is present on the web page and a “false” value if the web ...
Read more >Optional (Java Platform SE 8 ) - Oracle Help Center
A container object which may or may not contain a non-null value. If a value is present, isPresent() will return true and get()...
Read more >Array.prototype.some() - JavaScript - MDN Web Docs - Mozilla
It returns true if, in the array, it finds an element for which the provided function returns true; otherwise it returns false.
Read more >Python any() and all() Functions – Explained with Examples
In this tutorial, we'll learn about Python's any() and all() ... has False values at all positions where the * is present in...
Read more >C Programming Course Notes - Decisions and Branching
For interpretation, Zero is interpreted as false and anything non-zero is interpreted as true ... then the false-block of code is executed if...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
So I am happy to edit the documentation but I still have a question about this issue. As far as I can tell from the code,
.present
is an alias for.exist
which callswrapper.isPresent()
. But to use the matcher you don’t include the parenthesis in either case. So:Calling them like methods gives the error:
So I assume the documentation should reflect that. If this makes sense, I can go ahead and make the PR.
Both of those are built-in chai matchers, and since they return objects, that’s correct. In other words, those are not the correct matchers to be using. You should use
expect(wrapper.find('foo')).to.have.lengthOf(1)
or similar.