-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
New API: Alias exists
to isEmpty
#705
Comments
@chriscartlidge Thanks for a fantastic write up! You raised good points. I'll try and consolidate my thoughts.
The However, the main issue with changing the API to support In order to do this successfully, I would say we could just add the Before jumping into it though, let's make sure this API addition/change is in line with the other maintainers thoughts, @ljharb @aweary |
I'm fine with adding the "exists" API, and I agree with the hesitation around making a breaking change. |
exists
to isEmpty
@ljharb thanks! @christemple did you want to write the code and submit a PR? If you do, ping me and i'll work on getting it implemented. |
I also noticed that in the docs there is |
@themre in fact it's correct, using chai's |
I had a same problem. I tested with But I found interesting something that is I think we have to use (but |
@blainekasten @ljharb thanks for the feedback! I'll get a PR sorted this weekend with your suggestions. @blackpost38 I'll also have a look at |
Question: Should isEmpty() be replaced by an exist() function?
My personal experience
So I have been trying to test a React component that can return
false
in the render function [1].After reading the docs I seen
isEmpty
and thought this would be a perfect fit, until I read the example of how to useisEmpty
[2]It almost seems like
isEmpty()
in this scenario is closer toexists()
for example, the docs demonstrate searching for a child node that does not exist, and that is the only timeisEmpty()
will return true.The scenario I was hoping for is given the following component:
and the following test:
This results in a failure expecting false to equal true, because the
isEmpty()
call doesn't check what I assumed it to, it checks the length of the node, of which every wrapper never has 0, unless you do a.find
for a node within it that does not exist.Even doing the following still does not result in behaviour that I'd expect, it still returns
false
forisEmpty()
:After a while of reading through the docs I found a way of accomplishing what I was looking to do:
So, to wrap up...
isEmpty()
misleading?exist()
be more intuitive for ehatisEmpty()
is currently doing?isEmpty()
implementation suit better to checking.html() === null
?Thanks
Disclaimer: I have only started using enzyme and think it's a fantastic library
[1] https://facebook.github.io/react/docs/react-component.html#render
[2] http://airbnb.io/enzyme/docs/api/ReactWrapper/isEmpty.html
The text was updated successfully, but these errors were encountered: