-
Notifications
You must be signed in to change notification settings - Fork 276
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
containertoUNSAFE_rootto allow easy migration for users that might have valid uses forcontainerAPI.
- Potential valid uses seem to be custom queries atm.
- Make
containerlog deprecation message pointing toUNSAFE_root
- Create a new
rootreturn 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
pierrezimmermannbam and MattAgn
Metadata
Metadata
Assignees
Labels
No labels