From de7b7c029e8e8a0cd39e227c9bff62eea0975fe0 Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Thu, 23 Jun 2016 14:33:39 -0700 Subject: [PATCH] Pass custom testers to asymmetric testers This allows custom equality testers to affect asymmetric matches. This avoid suprises when combining addCustomEqualityTester with objectContaining or arrayContaining. Closes #1138 --- lib/jasmine-core/jasmine.js | 16 ++++++------- .../ArrayContainingSpec.js | 13 +++++++++++ .../ObjectContainingSpec.js | 13 +++++++++++ spec/core/integration/CustomMatchersSpec.js | 23 +++++++++++++++++++ spec/core/matchers/matchersUtilSpec.js | 10 ++++++++ .../asymmetric_equality/ArrayContaining.js | 4 ++-- .../asymmetric_equality/ObjectContaining.js | 4 ++-- src/core/matchers/matchersUtil.js | 8 +++---- 8 files changed, 75 insertions(+), 16 deletions(-) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index d299993f..b3b1106a 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -2642,13 +2642,13 @@ getJasmineRequireObj().ArrayContaining = function(j$) { this.sample = sample; } - ArrayContaining.prototype.asymmetricMatch = function(other) { + ArrayContaining.prototype.asymmetricMatch = function(other, customTesters) { var className = Object.prototype.toString.call(this.sample); if (className !== '[object Array]') { throw new Error('You must provide an array to arrayContaining, not \'' + this.sample + '\'.'); } for (var i = 0; i < this.sample.length; i++) { var item = this.sample[i]; - if (!j$.matchersUtil.contains(other, item)) { + if (!j$.matchersUtil.contains(other, item, customTesters)) { return false; } } @@ -2693,12 +2693,12 @@ getJasmineRequireObj().ObjectContaining = function(j$) { return hasProperty(getPrototype(obj), property); } - ObjectContaining.prototype.asymmetricMatch = function(other) { + ObjectContaining.prototype.asymmetricMatch = function(other, customTesters) { if (typeof(this.sample) !== 'object') { throw new Error('You must provide an object to objectContaining, not \''+this.sample+'\'.'); } for (var property in this.sample) { if (!hasProperty(other, property) || - !j$.matchersUtil.equals(this.sample[property], other[property])) { + !j$.matchersUtil.equals(this.sample[property], other[property], customTesters)) { return false; } } @@ -2813,7 +2813,7 @@ getJasmineRequireObj().matchersUtil = function(j$) { return obj && j$.isA_('Function', obj.asymmetricMatch); } - function asymmetricMatch(a, b) { + function asymmetricMatch(a, b, customTesters) { var asymmetricA = isAsymmetric(a), asymmetricB = isAsymmetric(b); @@ -2822,11 +2822,11 @@ getJasmineRequireObj().matchersUtil = function(j$) { } if (asymmetricA) { - return a.asymmetricMatch(b); + return a.asymmetricMatch(b, customTesters); } if (asymmetricB) { - return b.asymmetricMatch(a); + return b.asymmetricMatch(a, customTesters); } } @@ -2835,7 +2835,7 @@ getJasmineRequireObj().matchersUtil = function(j$) { function eq(a, b, aStack, bStack, customTesters) { var result = true; - var asymmetricResult = asymmetricMatch(a, b); + var asymmetricResult = asymmetricMatch(a, b, customTesters); if (!j$.util.isUndefined(asymmetricResult)) { return asymmetricResult; } diff --git a/spec/core/asymmetric_equality/ArrayContainingSpec.js b/spec/core/asymmetric_equality/ArrayContainingSpec.js index 999a6bf8..778eca43 100644 --- a/spec/core/asymmetric_equality/ArrayContainingSpec.js +++ b/spec/core/asymmetric_equality/ArrayContainingSpec.js @@ -36,4 +36,17 @@ describe("ArrayContaining", function() { expect(containing.jasmineToString()).toMatch("