Open
Description
@testing-library/jest-dom
version: 5.16.1node
version: v16.13.1yarn
version: 1.22.17
Relevant code or config:
import { expect } from '@jest/globals';
import '@testing-library/jest-dom';
expect(container).toHaveAttribute('hidden');
What you did:
I imported jest globals from '@jest/globals'
What happened:
I got the TypeScript error message: TS2339: Property 'toHaveAttribute' does not exist on type 'Matchers '.
Reproduction:
import { expect } from '@jest/globals';
import '@testing-library/jest-dom';
expect(container).toHaveAttribute('hidden');
Problem description:
The custom matchers provided by jest-dom cannot be used in TypeScript if the expect
is imported from @jest/globals
. Only the global expect
is modified, apparently.
Suggested solution:
Extend the interface of expect
in the @jest/globals
as well.