Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: re-write container API #1296

Closed
mdjastrzebski opened this issue Jan 27, 2023 · 3 comments · Fixed by #1298
Closed

RFC: re-write container API #1296

mdjastrzebski opened this issue Jan 27, 2023 · 3 comments · Fixed by #1298

Comments

@mdjastrzebski
Copy link
Member

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

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

@mdjastrzebski
Copy link
Member Author

@thymikee @AugustinLF @pierrezimmermannbam @MattAgn looks good, or do you see something worth changing?

@pierrezimmermannbam
Copy link
Collaborator

No this seems good to me!

@MattAgn
Copy link
Collaborator

MattAgn commented Jan 28, 2023

Seems good to me too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants