-
Couldn't load subscription status.
- Fork 411
Description
@testing-library/jest-domversion: 6.1.5nodeversion: N/A - using Bun 1.0.15jest(orvitest) version: N/A - usingbun testnpm(oryarn) version: N/A - using Bun 1.0.15@testing-library/reactversion: 14.1.2
Relevant code or config:
This code works in practice, it's just the types that are causing a problem:
import * as matchers from "@testing-library/jest-dom/matchers"; import { expect, mock, test } from "bun:test"; expect.extend(matchers); // ^ Argument of type 'TestingLibraryMatchers<any, void> & Record<string, any>' is not assignable to parameter of type 'ExpectExtendMatchers...What you did:
Tried to extend expect from bun:test with matchers from @testing-library/jest-dom/matchers.
I don't think this is specific to Bun, but they just added support for expect.extend so I thought I'd give it go.
What happened:
The TypeScript definitions for the "./matchers" export don't seem to match the implementations of the actual matchers.
Take toBeChecked, for example. The implementation is here:
Line 4 in b7b7c6a
| export function toBeChecked(element) { |
But the type definition doesn't include the element parameter:
Line 433 in b7b7c6a
| toBeChecked(): R |
Also, the R generic is specified as void in the export statement, so the return type is effectively missing as well. (Should be something like { pass: boolean; message: () => string; }.)
Lines 667 to 669 in b7b7c6a
| declare const matchers: matchers.TestingLibraryMatchers<any, void> & | |
| Record<string, any> | |
| export = matchers |
Reproduction:
See "Relevant code" section above.
Problem description:
Types should match the implementation.
Suggested solution:
https://github.com/testing-library/jest-dom/blob/main/types/matchers.d.ts should be updated to match the implementation of the matcher functions. If those types are correct in some other context (since they do seem to match the implementation when called as a property of an expect() result), then a separate definition file should be created for the "./matchers" export.