@@ -3,7 +3,7 @@ import { AssertionError } from 'node:assert'
3
3
import { stripVTControlCharacters } from 'node:util'
4
4
import { generateToBeMessage } from '@vitest/expect'
5
5
import { processError } from '@vitest/utils/error'
6
- import { beforeAll , describe , expect , it , vi } from 'vitest'
6
+ import { assert , beforeAll , describe , expect , it , vi } from 'vitest'
7
7
8
8
class TestError extends Error { }
9
9
@@ -606,6 +606,46 @@ describe('toSatisfy()', () => {
606
606
expect ( 1 ) . toSatisfy ( isOddMock )
607
607
expect ( isOddMock ) . toBeCalled ( )
608
608
} )
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
+ } )
609
649
} )
610
650
611
651
describe ( 'toHaveBeenCalled' , ( ) => {
0 commit comments