Skip to content

Queries and RenderResult use incompatible types #841

Closed
@pawbor

Description

@pawbor
  • @testing-library/react version: 11.2.2
  • Testing Framework and version: irrelevant
  • DOM Environment: irrelevant

Relevant code or config:

it('example', () => {
  const { container } = render(<span>foo</span>); // container type is Element

  getByText(container as HTMLElement, 'foo'); // can't use container here without casting to HTMLElement
});

What you did:

I tried to use container in custom query.

What happened:

Types do not match without manual casting.

Reproduction:

https://codesandbox.io/s/react-testing-library-demo-forked-bt601?file=/src/__tests__/hello.tsx

Suggested solution:

Loosening type requirements for element provided to Queries

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions