## 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: ```ts test('renders correctly', () => { const { container } = render(<Test />); expect(container).toBeEmptyElement() // this should fail, but passes }); ``` ## Suggested solution 1. 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` 3. Create a new `root` return from `render` (+ `screen.root`) that would expose root host component. This will allow to simplify writing component test, eg.: ```ts test('renders correctly', () => { render(<Test />); expect(screen.root).toBeEmptyElement() }); ``` ## Related Issues This should be released as part of v12. * Original discussion: https://github.com/callstack/react-native-testing-library/discussions/1289 * Issue that triggered the dicussion https://github.com/testing-library/jest-native/issues/141
Activity
mdjastrzebski commentedon Jan 27, 2023
@thymikee @AugustinLF @pierrezimmermannbam @MattAgn looks good, or do you see something worth changing?
pierrezimmermannbam commentedon Jan 27, 2023
No this seems good to me!
MattAgn commentedon Jan 28, 2023
Seems good to me too