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 to UNSAFE_root to allow easy migration for users that might have valid uses for container API.
- Potential valid uses seem to be custom queries atm.
- Make
container log deprecation message pointing to UNSAFE_root
- Create a new
root return from render (+ 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.
Summary
Current
containerAPI has following issues:Some users have been trying to use it in their component tests in a following way:
Suggested solution
containertoUNSAFE_rootto allow easy migration for users that might have valid uses forcontainerAPI.containerlog deprecation message pointing toUNSAFE_rootrootreturn fromrender(+screen.root) that would expose root host component. This will allow to simplify writing component test, eg.:Related Issues
This should be released as part of v12.