Description
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.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.