Skip to content

Commit 905ec05

Browse files
authored
fix: allow augmenting jest namespace for custom assertions (#3169)
1 parent 5436c73 commit 905ec05

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/vitest/src/types/global.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ declare global {
4444
// support augmenting jest.Matchers by other libraries
4545
namespace jest {
4646

47-
interface Matchers<_R, _T = {}> {}
47+
// eslint-disable-next-line unused-imports/no-unused-vars
48+
interface Matchers<R, T = {}> {}
4849
}
4950

5051
namespace Vi {

test/core/test/jest-expect.test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ interface CustomMatchers<R = unknown> {
1212
toBeTestedSync(): R
1313
toBeTestedPromise(): R
1414
}
15+
1516
declare global {
17+
namespace jest {
18+
interface Matchers<R> {
19+
toBeJestCompatible(): R
20+
}
21+
}
22+
1623
namespace Vi {
1724
interface JestAssertion extends CustomMatchers {}
1825
interface AsymmetricMatchersContaining extends CustomMatchers {}
@@ -182,6 +189,12 @@ describe('jest-expect', () => {
182189
message: () => 'toBeTestedPromise',
183190
})
184191
},
192+
toBeJestCompatible() {
193+
return {
194+
pass: true,
195+
message: () => '',
196+
}
197+
},
185198
})
186199

187200
expect(5).toBeDividedBy(5)
@@ -195,6 +208,8 @@ describe('jest-expect', () => {
195208
expect(() => expect(null).toBeTestedSync()).toThrowError('toBeTestedSync')
196209
await expect(async () => await expect(null).toBeTestedAsync()).rejects.toThrowError('toBeTestedAsync')
197210
await expect(async () => await expect(null).toBeTestedPromise()).rejects.toThrowError('toBeTestedPromise')
211+
212+
expect(expect).toBeJestCompatible()
198213
})
199214

200215
it('object', () => {

0 commit comments

Comments
 (0)