-
Notifications
You must be signed in to change notification settings - Fork 44
Description
react-nativeorexpo: vanilla RN@testing-library/react-nativeversion:11.5.0@testing-library/jest-nativeversion:5.3.1jest-preset: 'react-native'react-nativeversion: 70.6nodeversion: v16.15.1
Relevant 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:
import { render } from '@testing-library/react-native';
import { Text } from 'react-native';
function Test() {
return <Text>hello</Text>
}
test('renders correctly', () => {
const { container } = render(<Test />);
expect(container).toBeEmptyElement() // this should fail, but passes
});What you did:
First, I tried to use toBeEmptyElement in a test to assert that null 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:
import { render } from '@testing-library/react-native';
import { Text } from 'react-native';
function Test() {
return <Text>hello</Text>
}
test('renders correctly', () => {
const { container } = render(<Test />);
expect(container).toBeEmptyElement() // this should fail, but passes
});Problem description:
The matcher toBeEmptyElement doesn't appear to work as suggested in the docs/as expected.
Suggested solution:
I think the pass condition in toBeEmptyElement should be element?.children instead of element?.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.