@@ -3,7 +3,7 @@ import { AssertionError } from 'node:assert'
33import { stripVTControlCharacters } from 'node:util'
44import { generateToBeMessage } from '@vitest/expect'
55import { processError } from '@vitest/utils/error'
6- import { beforeAll , describe , expect , it , vi } from 'vitest'
6+ import { assert , beforeAll , describe , expect , it , vi } from 'vitest'
77
88class TestError extends Error { }
99
@@ -606,6 +606,46 @@ describe('toSatisfy()', () => {
606606 expect ( 1 ) . toSatisfy ( isOddMock )
607607 expect ( isOddMock ) . toBeCalled ( )
608608 } )
609+
610+ it ( 'asymmetric matcher' , ( ) => {
611+ expect ( { value : 1 } ) . toEqual ( { value : expect . toSatisfy ( isOdd ) } )
612+ expect ( ( ) => {
613+ expect ( { value : 2 } ) . toEqual ( { value : expect . toSatisfy ( isOdd , 'odd' ) } )
614+ } ) . toThrowErrorMatchingInlineSnapshot (
615+ `[AssertionError: expected { value: 2 } to deeply equal { value: toSatisfy{…} }]` ,
616+ )
617+
618+ expect ( ( ) => {
619+ throw new Error ( '1' )
620+ } ) . toThrow (
621+ expect . toSatisfy ( ( e ) => {
622+ assert ( e instanceof Error )
623+ expect ( e ) . toMatchObject ( { message : expect . toSatisfy ( isOdd ) } )
624+ return true
625+ } ) ,
626+ )
627+
628+ expect ( ( ) => {
629+ expect ( ( ) => {
630+ throw new Error ( '2' )
631+ } ) . toThrow (
632+ expect . toSatisfy ( ( e ) => {
633+ assert ( e instanceof Error )
634+ expect ( e ) . toMatchObject ( { message : expect . toSatisfy ( isOdd ) } )
635+ return true
636+ } ) ,
637+ )
638+ } ) . toThrowErrorMatchingInlineSnapshot (
639+ `[AssertionError: expected Error: 2 to match object { message: toSatisfy{…} }]` ,
640+ )
641+ } )
642+
643+ it ( 'error message' , ( ) => {
644+ snapshotError ( ( ) => expect ( 2 ) . toSatisfy ( isOdd ) )
645+ snapshotError ( ( ) => expect ( 2 ) . toSatisfy ( isOdd , 'ODD' ) )
646+ snapshotError ( ( ) => expect ( { value : 2 } ) . toEqual ( { value : expect . toSatisfy ( isOdd ) } ) )
647+ snapshotError ( ( ) => expect ( { value : 2 } ) . toEqual ( { value : expect . toSatisfy ( isOdd , 'ODD' ) } ) )
648+ } )
609649} )
610650
611651describe ( 'toHaveBeenCalled' , ( ) => {
0 commit comments