-
Notifications
You must be signed in to change notification settings - Fork 405
Vitest typings for jest-dom are broken in 6.6.2 when using "globalMode" #645
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
Comments
This was likely introduced by the change in #636. |
Adding |
Yes, I think it's working, but in the source code of /// <reference types="jest" /> If you happen to have |
I am running into the same issue with
Relevant code or config:// vitest-setup.js
import * as matchers from "vitest-axe/matchers";
import { expect } from "vitest";
expect.extend(matchers); // global.d.ts
import "vitest";
import type { AxeMatchers } from "vitest-axe/matchers";
declare module "vitest" {
export interface Assertion extends AxeMatchers {}
export interface AsymmetricMatchersContaining extends AxeMatchers {}
} What you did:I upgraded What happened:While tests ran successfully, during the build, TypeScript reported the following type errors:
This error occurred across multiple test files where the Reproduction:
Problem description:After upgrading to Suggested solution:The recent changes made in version 6.6.2 (https://github.com/testing-library/jest-dom/pull/636/files) on the |
We encountered this issue after upgrading to version 6.6.2. matchers like |
Fixed in #646 |
@testing-library/jest-dom
version: 6.6.2node
version: 20.10.0npm
(oryarn
) version: 10.2.3Relevant code or config / Reproduction:
minimun reproduce demo: https://stackblitz.com/edit/vitejs-vite-ydhnrx?file=src%2FApp.test.tsx
What you did:
Bootstramp a starter repo with vitest & testing-library (vitest should be in global mode, and there is no
import xxx from 'vitest'
in the whole project)Problem description / What happened:
The
toHaveTextContent
should be a matcher of expect, and also is working in runtime, but a type error is thrown.You can run
npm run build
to see the errorSuggested solution:
According to the documents of vitest, to extend a matcher, we have to import the
"vitest"
module otherwise the interface merge might not work as expectedSo we could add this line of code to top of the definition
You can try adding this in the stackbliz repo's dependency (jumping to the source code by ctrl + click the import) and run
npm run build
again, the type error should be fixedThe text was updated successfully, but these errors were encountered: