Skip to content

Commit

Permalink
fix: allow augmenting jest namespace for custom assertions (#3169)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Apr 11, 2023
1 parent 5436c73 commit 905ec05
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/vitest/src/types/global.ts
Expand Up @@ -44,7 +44,8 @@ declare global {
// support augmenting jest.Matchers by other libraries
namespace jest {

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

namespace Vi {
Expand Down
15 changes: 15 additions & 0 deletions test/core/test/jest-expect.test.ts
Expand Up @@ -12,7 +12,14 @@ interface CustomMatchers<R = unknown> {
toBeTestedSync(): R
toBeTestedPromise(): R
}

declare global {
namespace jest {
interface Matchers<R> {
toBeJestCompatible(): R
}
}

namespace Vi {
interface JestAssertion extends CustomMatchers {}
interface AsymmetricMatchersContaining extends CustomMatchers {}
Expand Down Expand Up @@ -182,6 +189,12 @@ describe('jest-expect', () => {
message: () => 'toBeTestedPromise',
})
},
toBeJestCompatible() {
return {
pass: true,
message: () => '',
}
},
})

expect(5).toBeDividedBy(5)
Expand All @@ -195,6 +208,8 @@ describe('jest-expect', () => {
expect(() => expect(null).toBeTestedSync()).toThrowError('toBeTestedSync')
await expect(async () => await expect(null).toBeTestedAsync()).rejects.toThrowError('toBeTestedAsync')
await expect(async () => await expect(null).toBeTestedPromise()).rejects.toThrowError('toBeTestedPromise')

expect(expect).toBeJestCompatible()
})

it('object', () => {
Expand Down

0 comments on commit 905ec05

Please sign in to comment.