-
-
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
Document how to test for null/false #52
Comments
@silvenon good question. I think I like changing At the moment, you could just check whether or not |
Thanks, I'll use that workaround in the meantime. I can send a PR if you guys decide you want that approach. |
I would love this as well! |
@ewendel doesn't a react component typically always return a single root element? i feel like React throws an invariant violation if not. |
No. You can return null or an empty string (perhaps also an empty array), and something in React will replace this with a This is essential in components that handle conditional rendering - its a pity that enzyme apparently doesn't support this. |
@ewendel right, i mean that either it returns "nothing" - which could be null, or an empty string, or undefined, possibly a few others - or a single component. |
You are absolutely correct, I don't know what I was talking about. I have an |
Thanks, @lelandrichardson your answers works for me. |
|
Also |
For me, |
When using getNode(), a warning says to use getElement() instead. |
Can you not also do |
|
Yep, Rich @fauna5 was using the old API, it's now wrapper.getElement()
// In Jest
expect(wrapper.getElement()).toBe(null); Which as mentioned is semantically clear. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
In case this helps anyone else. I ended up doing this:
Or if this is a bad idea, then let me know. |
@ahuggins I'd suggest not using |
I would like to add to the docs a good way to test for
null
, but I'm not sure which one is it.This is the component:
I want to test if setting the flag to
true
will returnnull
:What is the correct way to do it? Would it perhaps be better if
wrapper.type()
returnednull
instead of throwing?The text was updated successfully, but these errors were encountered: