Skip to content

RFC: re-write container API #1296

Description

@mdjastrzebski

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions