@@ -3,21 +3,23 @@ import { assertTypes, getColors } from '@vitest/utils'
33import type { Constructable } from '@vitest/utils'
44import type { EnhancedSpy } from '@vitest/spy'
55import { isMockFunction } from '@vitest/spy'
6+ import type { Test } from '@vitest/runner'
67import type { Assertion , ChaiPlugin } from './types'
78import { arrayBufferEquality , generateToBeMessage , iterableEquality , equals as jestEquals , sparseArrayEquality , subsetEquality , typeEquality } from './jest-utils'
89import type { AsymmetricMatcher } from './jest-asymmetric-matchers'
910import { diff , stringify } from './jest-matcher-utils'
1011import { JEST_MATCHERS_OBJECT } from './constants'
11- import { recordAsyncExpect } from './utils'
12+ import { recordAsyncExpect , wrapSoft } from './utils'
1213
1314// Jest Expect Compact
1415export const JestChaiExpect : ChaiPlugin = ( chai , utils ) => {
1516 const c = ( ) => getColors ( )
1617
1718 function def ( name : keyof Assertion | ( keyof Assertion ) [ ] , fn : ( ( this : Chai . AssertionStatic & Assertion , ...args : any [ ] ) => any ) ) {
1819 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 )
2123 }
2224
2325 if ( Array . isArray ( name ) )
@@ -636,7 +638,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
636638 utils . addProperty ( chai . Assertion . prototype , 'resolves' , function __VITEST_RESOLVES__ ( this : any ) {
637639 utils . flag ( this , 'promise' , 'resolves' )
638640 utils . flag ( this , 'error' , new Error ( 'resolves' ) )
639- const test = utils . flag ( this , 'vitest-test' )
641+ const test : Test = utils . flag ( this , 'vitest-test' )
640642 const obj = utils . flag ( this , 'object' )
641643
642644 if ( typeof obj ?. then !== 'function' )
@@ -671,7 +673,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
671673 utils . addProperty ( chai . Assertion . prototype , 'rejects' , function __VITEST_REJECTS__ ( this : any ) {
672674 utils . flag ( this , 'promise' , 'rejects' )
673675 utils . flag ( this , 'error' , new Error ( 'rejects' ) )
674- const test = utils . flag ( this , 'vitest-test' )
676+ const test : Test = utils . flag ( this , 'vitest-test' )
675677 const obj = utils . flag ( this , 'object' )
676678 const wrapper = typeof obj === 'function' ? obj ( ) : obj // for jest compat
677679
0 commit comments