@@ -576,12 +576,19 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
576
576
throw new AssertionError ( msg )
577
577
}
578
578
} )
579
+
580
+ // manually compare array elements since `jestEquals` cannot
581
+ // apply assymetric matcher to `undefined` array element.
582
+ function equalsArgumentArray ( a : unknown [ ] , b : unknown [ ] ) {
583
+ return a . length === b . length && a . every ( ( aItem , i ) =>
584
+ jestEquals ( aItem , b [ i ] , [ ...customTesters , iterableEquality ] ) ,
585
+ )
586
+ }
587
+
579
588
def ( [ 'toHaveBeenCalledWith' , 'toBeCalledWith' ] , function ( ...args ) {
580
589
const spy = getSpy ( this )
581
590
const spyName = spy . getMockName ( )
582
- const pass = spy . mock . calls . some ( callArg =>
583
- jestEquals ( callArg , args , [ ...customTesters , iterableEquality ] ) ,
584
- )
591
+ const pass = spy . mock . calls . some ( callArg => equalsArgumentArray ( callArg , args ) )
585
592
const isNot = utils . flag ( this , 'negate' ) as boolean
586
593
587
594
const msg = utils . getMessage ( this , [
@@ -599,9 +606,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
599
606
const spy = getSpy ( this )
600
607
const spyName = spy . getMockName ( )
601
608
const callCount = spy . mock . calls . length
602
- const hasCallWithArgs = spy . mock . calls . some ( callArg =>
603
- jestEquals ( callArg , args , [ ...customTesters , iterableEquality ] ) ,
604
- )
609
+ const hasCallWithArgs = spy . mock . calls . some ( callArg => equalsArgumentArray ( callArg , args ) )
605
610
const pass = hasCallWithArgs && callCount === 1
606
611
const isNot = utils . flag ( this , 'negate' ) as boolean
607
612
@@ -625,7 +630,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
625
630
const callCount = spy . mock . calls . length
626
631
const isCalled = times <= callCount
627
632
this . assert (
628
- jestEquals ( nthCall , args , [ ... customTesters , iterableEquality ] ) ,
633
+ nthCall && equalsArgumentArray ( nthCall , args ) ,
629
634
`expected ${ ordinalOf (
630
635
times ,
631
636
) } "${ spyName } " call to have been called with #{exp}${
@@ -648,7 +653,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
648
653
const lastCall = spy . mock . calls [ spy . mock . calls . length - 1 ]
649
654
650
655
this . assert (
651
- jestEquals ( lastCall , args , [ ... customTesters , iterableEquality ] ) ,
656
+ lastCall && equalsArgumentArray ( lastCall , args ) ,
652
657
`expected last "${ spyName } " call to have been called with #{exp}` ,
653
658
`expected last "${ spyName } " call to not have been called with #{exp}` ,
654
659
args ,
0 commit comments