question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:open
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
droartycommented, Jul 21, 2016

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 calls wrapper.isPresent(). But to use the matcher you don’t include the parenthesis in either case. So:

expect(wrapper.find(".my-class")).to.exist  // Passes
expect(wrapper.find(".my-class")).to.be.present  // Passes
expect(wrapper.find(".my-class")).to.exist()  // Fails
expect(wrapper.find(".my-class")).to.be.present()  // Fails

Calling them like methods gives the error:

undefined is not a constructor (evaluating 'expect(wrapper.find(".my-class")).to.be.present()')

So I assume the documentation should reflect that. If this makes sense, I can go ahead and make the PR.

1reaction
ljharbcommented, Jun 3, 2016

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found