Skip to content

Make screen query methods generic #1033

Closed
@nstepien

Description

@nstepien
  • @testing-library/dom version: 8.5.0
  • Testing Framework and version: jest@27.2.0
  • DOM Environment: jsdom

Relevant code or config:

import { screen } from '@testing-library/dom';

screen.getByText<HTMLElement>('test');

What you did:

Defined a type argument for getByText

What happened:

> tsc

test.ts:3:18 - error TS2558: Expected 0 type arguments, but got 1.

3 screen.getByText<HTMLElement>('test');
                   ~~~~~~~~~~~

Reproduction:

import { screen } from '@testing-library/dom';

screen.getByText<HTMLElement>('test');

Problem description:

While the methods are generic, the way they're redefined on the screen object for example makes them lose their genericness.
Original request: #615
PR which made the methods generic: #1023

Suggested solution:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions