@@ -576,12 +576,19 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
576576 throw new AssertionError ( msg )
577577 }
578578 } )
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+
579588 def ( [ 'toHaveBeenCalledWith' , 'toBeCalledWith' ] , function ( ...args ) {
580589 const spy = getSpy ( this )
581590 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 ) )
585592 const isNot = utils . flag ( this , 'negate' ) as boolean
586593
587594 const msg = utils . getMessage ( this , [
@@ -599,9 +606,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
599606 const spy = getSpy ( this )
600607 const spyName = spy . getMockName ( )
601608 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 ) )
605610 const pass = hasCallWithArgs && callCount === 1
606611 const isNot = utils . flag ( this , 'negate' ) as boolean
607612
@@ -625,7 +630,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
625630 const callCount = spy . mock . calls . length
626631 const isCalled = times <= callCount
627632 this . assert (
628- jestEquals ( nthCall , args , [ ... customTesters , iterableEquality ] ) ,
633+ nthCall && equalsArgumentArray ( nthCall , args ) ,
629634 `expected ${ ordinalOf (
630635 times ,
631636 ) } "${ spyName } " call to have been called with #{exp}${
@@ -648,7 +653,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
648653 const lastCall = spy . mock . calls [ spy . mock . calls . length - 1 ]
649654
650655 this . assert (
651- jestEquals ( lastCall , args , [ ... customTesters , iterableEquality ] ) ,
656+ lastCall && equalsArgumentArray ( lastCall , args ) ,
652657 `expected last "${ spyName } " call to have been called with #{exp}` ,
653658 `expected last "${ spyName } " call to not have been called with #{exp}` ,
654659 args ,
0 commit comments