-
Notifications
You must be signed in to change notification settings - Fork 401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript types for the "./matchers"
export don't match implementations
#554
Labels
Comments
I tried the same thing and got the similar problem. Here is the related test: import {
expect,
test,
} from 'bun:test'
import {
render,
screen,
} from '@testing-library/react'
import * as extensions from '@testing-library/jest-dom/matchers'
import App from './App'
expect.extend(extensions)
test('renders', async () => {
render(<App />);
expect(screen.getByText('Click on the Vite and React logos to learn more')).toBeInTheDocument();
}) Running
However, the test is running as expected. Only the typing is the issue here. |
4 tasks
@soullivaneuh I just submitted #566 to address this issue. |
🎉 This issue has been resolved in version 6.2.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@testing-library/jest-dom
version: 6.1.5node
version: N/A - using Bun 1.0.15jest
(orvitest
) version: N/A - usingbun test
npm
(oryarn
) version: N/A - using Bun 1.0.15@testing-library/react
version: 14.1.2Relevant code or config:
This code works in practice, it's just the types that are causing a problem:
What you did:
Tried to extend
expect
frombun: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:jest-dom/src/to-be-checked.js
Line 4 in b7b7c6a
But the type definition doesn't include the
element
parameter:jest-dom/types/matchers.d.ts
Line 433 in b7b7c6a
Also, the
R
generic is specified asvoid
in theexport
statement, so the return type is effectively missing as well. (Should be something like{ pass: boolean; message: () => string; }
.)jest-dom/types/matchers.d.ts
Lines 667 to 669 in b7b7c6a
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.The text was updated successfully, but these errors were encountered: