11/* eslint-disable unicorn/no-instanceof-builtins -- we check both */
22
3- import type { ChaiPlugin , MatcherState } from './types'
3+ import type { ChaiPlugin , MatcherState , Tester } from './types'
44import { GLOBAL_EXPECT } from './constants'
55import {
66 diff ,
@@ -19,7 +19,7 @@ import {
1919import { getState } from './state'
2020
2121export interface AsymmetricMatcherInterface {
22- asymmetricMatch : ( other : unknown ) => boolean
22+ asymmetricMatch : ( other : unknown , customTesters ?: Array < Tester > ) => boolean
2323 toString : ( ) => string
2424 getExpectedType ?: ( ) => string
2525 toAsymmetricMatcher ?: ( ) => string
@@ -50,7 +50,7 @@ export abstract class AsymmetricMatcher<
5050 }
5151 }
5252
53- abstract asymmetricMatch ( other : unknown ) : boolean
53+ abstract asymmetricMatch ( other : unknown , customTesters ?: Array < Tester > ) : boolean
5454 abstract toString ( ) : string
5555 getExpectedType ?( ) : string
5656 toAsymmetricMatcher ?( ) : string
@@ -147,7 +147,7 @@ export class ObjectContaining extends AsymmetricMatcher<
147147 ]
148148 }
149149
150- asymmetricMatch ( other : any ) : boolean {
150+ asymmetricMatch ( other : any , customTesters ?: Array < Tester > ) : boolean {
151151 if ( typeof this . sample !== 'object' ) {
152152 throw new TypeError (
153153 `You must provide an object to ${ this . toString ( ) } , not '${ typeof this
@@ -157,7 +157,6 @@ export class ObjectContaining extends AsymmetricMatcher<
157157
158158 let result = true
159159
160- const matcherContext = this . getMatcherContext ( )
161160 const properties = this . getProperties ( this . sample )
162161 for ( const property of properties ) {
163162 if (
@@ -171,7 +170,7 @@ export class ObjectContaining extends AsymmetricMatcher<
171170 if ( ! equals (
172171 value ,
173172 otherValue ,
174- matcherContext . customTesters ,
173+ customTesters ,
175174 )
176175 ) {
177176 result = false
@@ -196,21 +195,20 @@ export class ArrayContaining<T = unknown> extends AsymmetricMatcher<Array<T>> {
196195 super ( sample , inverse )
197196 }
198197
199- asymmetricMatch ( other : Array < T > ) : boolean {
198+ asymmetricMatch ( other : Array < T > , customTesters ?: Array < Tester > ) : boolean {
200199 if ( ! Array . isArray ( this . sample ) ) {
201200 throw new TypeError (
202201 `You must provide an array to ${ this . toString ( ) } , not '${ typeof this
203202 . sample } '.`,
204203 )
205204 }
206205
207- const matcherContext = this . getMatcherContext ( )
208206 const result
209207 = this . sample . length === 0
210208 || ( Array . isArray ( other )
211209 && this . sample . every ( item =>
212210 other . some ( another =>
213- equals ( item , another , matcherContext . customTesters ) ,
211+ equals ( item , another , customTesters ) ,
214212 ) ,
215213 ) )
216214
0 commit comments