@@ -6,7 +6,7 @@ import type { Test } from '@vitest/runner'
66import type { Assertion , ChaiPlugin } from './types'
77import { arrayBufferEquality , generateToBeMessage , iterableEquality , equals as jestEquals , sparseArrayEquality , subsetEquality , typeEquality } from './jest-utils'
88import type { AsymmetricMatcher } from './jest-asymmetric-matchers'
9- import { diff , stringify } from './jest-matcher-utils'
9+ import { diff , getCustomEqualityTesters , stringify } from './jest-matcher-utils'
1010import { JEST_MATCHERS_OBJECT } from './constants'
1111import { recordAsyncExpect , wrapSoft } from './utils'
1212
@@ -23,6 +23,7 @@ declare class DOMTokenList {
2323export const JestChaiExpect : ChaiPlugin = ( chai , utils ) => {
2424 const { AssertionError } = chai
2525 const c = ( ) => getColors ( )
26+ const customTesters = getCustomEqualityTesters ( )
2627
2728 function def ( name : keyof Assertion | ( keyof Assertion ) [ ] , fn : ( ( this : Chai . AssertionStatic & Assertion , ...args : any [ ] ) => any ) ) {
2829 const addMethod = ( n : keyof Assertion ) => {
@@ -80,7 +81,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
8081 const equal = jestEquals (
8182 actual ,
8283 expected ,
83- [ iterableEquality ] ,
84+ [ ... customTesters , iterableEquality ] ,
8485 )
8586
8687 return this . assert (
@@ -98,6 +99,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
9899 obj ,
99100 expected ,
100101 [
102+ ...customTesters ,
101103 iterableEquality ,
102104 typeEquality ,
103105 sparseArrayEquality ,
@@ -125,6 +127,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
125127 actual ,
126128 expected ,
127129 [
130+ ...customTesters ,
128131 iterableEquality ,
129132 typeEquality ,
130133 sparseArrayEquality ,
@@ -140,7 +143,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
140143 const toEqualPass = jestEquals (
141144 actual ,
142145 expected ,
143- [ iterableEquality ] ,
146+ [ ... customTesters , iterableEquality ] ,
144147 )
145148
146149 if ( toEqualPass )
@@ -159,7 +162,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
159162 def ( 'toMatchObject' , function ( expected ) {
160163 const actual = this . _obj
161164 return this . assert (
162- jestEquals ( actual , expected , [ iterableEquality , subsetEquality ] ) ,
165+ jestEquals ( actual , expected , [ ... customTesters , iterableEquality , subsetEquality ] ) ,
163166 'expected #{this} to match object #{exp}' ,
164167 'expected #{this} to not match object #{exp}' ,
165168 expected ,
@@ -208,7 +211,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
208211 def ( 'toContainEqual' , function ( expected ) {
209212 const obj = utils . flag ( this , 'object' )
210213 const index = Array . from ( obj ) . findIndex ( ( item ) => {
211- return jestEquals ( item , expected )
214+ return jestEquals ( item , expected , customTesters )
212215 } )
213216
214217 this . assert (
@@ -339,7 +342,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
339342 return utils . getPathInfo ( actual , propertyName )
340343 }
341344 const { value, exists } = getValue ( )
342- const pass = exists && ( args . length === 1 || jestEquals ( expected , value ) )
345+ const pass = exists && ( args . length === 1 || jestEquals ( expected , value , customTesters ) )
343346
344347 const valueString = args . length === 1 ? '' : ` with value ${ utils . objDisplay ( expected ) } `
345348
@@ -482,7 +485,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
482485 def ( [ 'toHaveBeenCalledWith' , 'toBeCalledWith' ] , function ( ...args ) {
483486 const spy = getSpy ( this )
484487 const spyName = spy . getMockName ( )
485- const pass = spy . mock . calls . some ( callArg => jestEquals ( callArg , args , [ iterableEquality ] ) )
488+ const pass = spy . mock . calls . some ( callArg => jestEquals ( callArg , args , [ ... customTesters , iterableEquality ] ) )
486489 const isNot = utils . flag ( this , 'negate' ) as boolean
487490
488491 const msg = utils . getMessage (
@@ -504,7 +507,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
504507 const nthCall = spy . mock . calls [ times - 1 ]
505508
506509 this . assert (
507- jestEquals ( nthCall , args , [ iterableEquality ] ) ,
510+ jestEquals ( nthCall , args , [ ... customTesters , iterableEquality ] ) ,
508511 `expected ${ ordinalOf ( times ) } "${ spyName } " call to have been called with #{exp}` ,
509512 `expected ${ ordinalOf ( times ) } "${ spyName } " call to not have been called with #{exp}` ,
510513 args ,
@@ -517,7 +520,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
517520 const lastCall = spy . mock . calls [ spy . mock . calls . length - 1 ]
518521
519522 this . assert (
520- jestEquals ( lastCall , args , [ iterableEquality ] ) ,
523+ jestEquals ( lastCall , args , [ ... customTesters , iterableEquality ] ) ,
521524 `expected last "${ spyName } " call to have been called with #{exp}` ,
522525 `expected last "${ spyName } " call to not have been called with #{exp}` ,
523526 args ,
0 commit comments