diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 616c4961..e5af1c85 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -662,12 +662,6 @@ getJasmineRequireObj().util = function(j$) { return descriptor; }; - util.objectDifference = function(obj, toRemove) { - return j$.MatchersUtil.keys(obj) - .filter(key => !util.has(toRemove, key)) - .map(key => [key, obj[key]]); - }; - util.has = function(obj, key) { return Object.prototype.hasOwnProperty.call(obj, key); }; @@ -5609,9 +5603,17 @@ getJasmineRequireObj().MatchersUtil = function(j$) { return typeof obj === 'function'; } + // Returns an array of [k, v] pairs for eacch property that's in objA + // and not in objB. + function extraKeysAndValues(objA, objB) { + return MatchersUtil.keys(objA) + .filter(key => !j$.util.has(objB, key)) + .map(key => [key, objA[key]]); + } + function objectKeysAreDifferentFormatter(pp, actual, expected, path) { - var missingProperties = j$.util.objectDifference(expected, actual), - extraProperties = j$.util.objectDifference(actual, expected), + var missingProperties = extraKeysAndValues(expected, actual), + extraProperties = extraKeysAndValues(actual, expected), missingPropertiesMessage = formatKeyValuePairs(pp, missingProperties), extraPropertiesMessage = formatKeyValuePairs(pp, extraProperties), messages = []; diff --git a/spec/core/UtilSpec.js b/spec/core/UtilSpec.js index 36f4e8ba..3374479d 100644 --- a/spec/core/UtilSpec.js +++ b/spec/core/UtilSpec.js @@ -183,66 +183,6 @@ describe('util', function() { }); }); - describe('objectDifference', function() { - it('given two objects A and B, returns the properties in A not present in B', function() { - const a = { - foo: 3, - bar: 4, - baz: 5 - }; - - const b = { - bar: 6, - quux: 7 - }; - - expect(jasmineUnderTest.util.objectDifference(a, b)).toEqual([ - ['foo', 3], - ['baz', 5] - ]); - }); - - it('includes Symbol keys', function() { - const missing = Symbol('missing'); - const both = Symbol('both'); - const symbolDuplicated1 = Symbol('symbolDuplicated'); - const symbolDuplicated2 = Symbol('symbolDuplicated'); - const added = Symbol('added'); - const a = { - [missing]: 1, - [both]: 2, - [symbolDuplicated1]: 3 - }; - - const b = { - [both]: 'anything', - [symbolDuplicated2]: 4, - [added]: 5 - }; - - expect(jasmineUnderTest.util.objectDifference(a, b)).toEqual([ - [missing, 1], - [symbolDuplicated1, 3] - ]); - }); - - it('only looks at own properties of both objects', function() { - function Foo() {} - - Foo.prototype.x = 1; - Foo.prototype.y = 2; - - const a = new Foo(); - a.x = 1; - - const b = new Foo(); - b.y = 2; - - expect(jasmineUnderTest.util.objectDifference(a, b)).toEqual([['x', 1]]); - expect(jasmineUnderTest.util.objectDifference(b, a)).toEqual([['y', 2]]); - }); - }); - describe('jasmineFile', function() { it('returns the file containing jasmine.util', function() { // Chrome sometimes reports foo.js as foo.js/, so tolerate diff --git a/src/core/matchers/matchersUtil.js b/src/core/matchers/matchersUtil.js index 0bf2a57f..9a3a586e 100644 --- a/src/core/matchers/matchersUtil.js +++ b/src/core/matchers/matchersUtil.js @@ -558,9 +558,17 @@ getJasmineRequireObj().MatchersUtil = function(j$) { return typeof obj === 'function'; } + // Returns an array of [k, v] pairs for eacch property that's in objA + // and not in objB. + function extraKeysAndValues(objA, objB) { + return MatchersUtil.keys(objA) + .filter(key => !j$.util.has(objB, key)) + .map(key => [key, objA[key]]); + } + function objectKeysAreDifferentFormatter(pp, actual, expected, path) { - var missingProperties = j$.util.objectDifference(expected, actual), - extraProperties = j$.util.objectDifference(actual, expected), + var missingProperties = extraKeysAndValues(expected, actual), + extraProperties = extraKeysAndValues(actual, expected), missingPropertiesMessage = formatKeyValuePairs(pp, missingProperties), extraPropertiesMessage = formatKeyValuePairs(pp, extraProperties), messages = []; diff --git a/src/core/util.js b/src/core/util.js index f2b7eb7d..cd4170d4 100644 --- a/src/core/util.js +++ b/src/core/util.js @@ -75,12 +75,6 @@ getJasmineRequireObj().util = function(j$) { return descriptor; }; - util.objectDifference = function(obj, toRemove) { - return j$.MatchersUtil.keys(obj) - .filter(key => !util.has(toRemove, key)) - .map(key => [key, obj[key]]); - }; - util.has = function(obj, key) { return Object.prototype.hasOwnProperty.call(obj, key); };