@@ -3,21 +3,23 @@ import { assertTypes, getColors } from '@vitest/utils'
3
3
import type { Constructable } from '@vitest/utils'
4
4
import type { EnhancedSpy } from '@vitest/spy'
5
5
import { isMockFunction } from '@vitest/spy'
6
+ import type { Test } from '@vitest/runner'
6
7
import type { Assertion , ChaiPlugin } from './types'
7
8
import { arrayBufferEquality , generateToBeMessage , iterableEquality , equals as jestEquals , sparseArrayEquality , subsetEquality , typeEquality } from './jest-utils'
8
9
import type { AsymmetricMatcher } from './jest-asymmetric-matchers'
9
10
import { diff , stringify } from './jest-matcher-utils'
10
11
import { JEST_MATCHERS_OBJECT } from './constants'
11
- import { recordAsyncExpect } from './utils'
12
+ import { recordAsyncExpect , wrapSoft } from './utils'
12
13
13
14
// Jest Expect Compact
14
15
export const JestChaiExpect : ChaiPlugin = ( chai , utils ) => {
15
16
const c = ( ) => getColors ( )
16
17
17
18
function def ( name : keyof Assertion | ( keyof Assertion ) [ ] , fn : ( ( this : Chai . AssertionStatic & Assertion , ...args : any [ ] ) => any ) ) {
18
19
const addMethod = ( n : keyof Assertion ) => {
19
- utils . addMethod ( chai . Assertion . prototype , n , fn )
20
- utils . addMethod ( ( globalThis as any ) [ JEST_MATCHERS_OBJECT ] . matchers , n , fn )
20
+ const softWrapper = wrapSoft ( utils , fn )
21
+ utils . addMethod ( chai . Assertion . prototype , n , softWrapper )
22
+ utils . addMethod ( ( globalThis as any ) [ JEST_MATCHERS_OBJECT ] . matchers , n , softWrapper )
21
23
}
22
24
23
25
if ( Array . isArray ( name ) )
@@ -636,7 +638,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
636
638
utils . addProperty ( chai . Assertion . prototype , 'resolves' , function __VITEST_RESOLVES__ ( this : any ) {
637
639
utils . flag ( this , 'promise' , 'resolves' )
638
640
utils . flag ( this , 'error' , new Error ( 'resolves' ) )
639
- const test = utils . flag ( this , 'vitest-test' )
641
+ const test : Test = utils . flag ( this , 'vitest-test' )
640
642
const obj = utils . flag ( this , 'object' )
641
643
642
644
if ( typeof obj ?. then !== 'function' )
@@ -671,7 +673,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
671
673
utils . addProperty ( chai . Assertion . prototype , 'rejects' , function __VITEST_REJECTS__ ( this : any ) {
672
674
utils . flag ( this , 'promise' , 'rejects' )
673
675
utils . flag ( this , 'error' , new Error ( 'rejects' ) )
674
- const test = utils . flag ( this , 'vitest-test' )
676
+ const test : Test = utils . flag ( this , 'vitest-test' )
675
677
const obj = utils . flag ( this , 'object' )
676
678
const wrapper = typeof obj === 'function' ? obj ( ) : obj // for jest compat
677
679
0 commit comments