-
Notifications
You must be signed in to change notification settings - Fork 44
toBeEmptyElement isn't working as expected #141
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
Comments
I think you've found a valid bug. However, the case might be more complex than the solution you suggested. TLDR: do not invoke any assertions on I'll try to explain it briefly:
So when invoking the
Both can give wrong results in certain situations. The actual solution would consist of following changes:
The last point is actually something actionable. But would need to include a compatibility hack to work correctly with composite |
This should no longer happen with RNTL v12+ as all queries now return host elements, as well as |
react-native
orexpo
: vanilla RN@testing-library/react-native
version:11.5.0
@testing-library/jest-native
version:5.3.1
jest-preset
: 'react-native'react-native
version: 70.6node
version: v16.15.1Relevant code or config:
The relevant code appears to be here: https://github.com/testing-library/jest-native/blob/main/src/to-be-empty-element.ts#L9
Here's a minimal repro:
What you did:
First, I tried to use
toBeEmptyElement
in a test to assert thatnull
was returned from a component. Noticed it passed (yay!), then I tried a negative test to make sure that the test failed if non-null was returned. The test still passed, when a failure was expected 🤔.What happened:
The referenced test/repro code is passing, when a failure is expected.
Reproduction:
Problem description:
The matcher
toBeEmptyElement
doesn't appear to work as suggested in the docs/as expected.Suggested solution:
I think the
pass
condition intoBeEmptyElement
should beelement?.children
instead ofelement?.props?.children
?Relevant code: https://github.com/testing-library/jest-native/blob/main/src/to-be-empty-element.ts#L9
Can you help us fix this issue by submitting a pull request?
I believe so - I can try to find some time.
The text was updated successfully, but these errors were encountered: