Skip to content

Commit ae353c6

Browse files
fix(headless): register jest-dom matcher types for vitest 4 (#8821)
1 parent 5684ed9 commit ae353c6

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

packages/headless/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@
5353
"scripts": {
5454
"build": "rm -rf dist && vite build",
5555
"dev": "vite build --watch",
56-
"lint": "eslint src",
57-
"test": "vitest run"
56+
"lint": "eslint src && pnpm typecheck",
57+
"test": "vitest run",
58+
"typecheck": "tsc --noEmit"
5859
},
5960
"dependencies": {
6061
"@floating-ui/react": "catalog:repo"
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
1-
import '@testing-library/jest-dom/vitest';
1+
import 'vitest';
22
import './vitest-axe';
3+
4+
import type { TestingLibraryMatchers } from '@testing-library/jest-dom/matchers';
5+
6+
// `@testing-library/jest-dom/vitest` registers its matcher types via a
7+
// triple-slash `/// <reference>` to an internal declaration file, which does not
8+
// reliably apply when re-exported through this package's test setup. Declare the
9+
// `vitest` module augmentation explicitly so `expect(...).toBeInTheDocument()` and
10+
// friends are typed. `import 'vitest'` keeps this file a module augmentation
11+
// rather than an ambient module declaration that would shadow vitest's own types.
12+
declare module 'vitest' {
13+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
14+
interface Assertion<T = any> extends TestingLibraryMatchers<any, T> {}
15+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
16+
interface AsymmetricMatchersContaining extends TestingLibraryMatchers<any, any> {}
17+
}

0 commit comments

Comments
 (0)