Allow libraries to avoid "Passing custom equality testers to MatchersUtil#contains is deprecated" while remaining compatible with older jasmine versions

Previously, a custom matcher library that wanted to remain compatible with
Jasmine <= 3.5.x could not know whether or not Jasmine expected it to pass
custom equality testers to MatchersUtil#contains. Passing them would produce
a deprecation warning in newer versions and not passing them would break
compatibility with older versions. Now we use matcher factory arity to
determine whether to pass custom equality testers to the factory, which
allows libraries to do something like this:

function matcherFactory(util) {
   const customEqualityTesters = arguments[1];
   // customEqualityTesters will be undefined in newer versions of Jasmine
   // and defined in older versions that expect it to be passed back to
   // MatchersUtil#equals.
}
This commit is contained in:
Steve Gravrock
2020-01-18 14:16:15 -08:00
committed by Steve Gravrock
parent 9aed55bb91
commit 18b2646d1d
7 changed files with 153 additions and 35 deletions

View File

@@ -20,7 +20,15 @@ getJasmineRequireObj().Expector = function(j$) {
this.args.unshift(this.actual);
var matcher = matcherFactory(this.matchersUtil, this.customEqualityTesters);
// TODO: Remove support for passing customEqualityTesters in the next major release.
var matcher;
if (matcherFactory.length >= 2) {
matcher = matcherFactory(this.matchersUtil, this.customEqualityTesters);
} else {
matcher = matcherFactory(this.matchersUtil);
}
var comparisonFunc = this.filters.selectComparisonFunc(matcher);
return comparisonFunc || matcher.compare;
};