Closed
Description
Summary
Current container
API has following issues:
- it returns composite element, while we try to avoid return such components
- it is not behaving the same as RTL API of the same name, as RTL returns an element containing the rendered elements
Some users have been trying to use it in their component tests in a following way:
test('renders correctly', () => {
const { container } = render(<Test />);
expect(container).toBeEmptyElement() // this should fail, but passes
});
Suggested solution
- Rename
container
toUNSAFE_root
to allow easy migration for users that might have valid uses forcontainer
API.
- Potential valid uses seem to be custom queries atm.
- Make
container
log deprecation message pointing toUNSAFE_root
- Create a new
root
return fromrender
(+screen.root
) that would expose root host component. This will allow to simplify writing component test, eg.:
test('renders correctly', () => {
render(<Test />);
expect(screen.root).toBeEmptyElement()
});
Related Issues
This should be released as part of v12.
- Original discussion: Container API is broken #1289
- Issue that triggered the dicussion toBeEmptyElement isn't working as expected testing-library/jest-native#141
Metadata
Metadata
Assignees
Labels
No labels