@@ -663,15 +663,9 @@ getJasmineRequireObj().util = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
util.objectDifference = function(obj, toRemove) {
|
util.objectDifference = function(obj, toRemove) {
|
||||||
var diff = {};
|
return j$.MatchersUtil.keys(obj)
|
||||||
|
.filter(key => !util.has(toRemove, key))
|
||||||
for (var key in obj) {
|
.map(key => [key, obj[key]]);
|
||||||
if (util.has(obj, key) && !util.has(toRemove, key)) {
|
|
||||||
diff[key] = obj[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return diff;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
util.has = function(obj, key) {
|
util.has = function(obj, key) {
|
||||||
@@ -5667,11 +5661,13 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatKeyValuePairs(pp, obj) {
|
function formatKeyValuePairs(pp, keyValuePairs) {
|
||||||
var formatted = '';
|
let formatted = '';
|
||||||
for (var key in obj) {
|
|
||||||
formatted += '\n ' + key + ': ' + pp(obj[key]);
|
for (const [key, value] of keyValuePairs) {
|
||||||
|
formatted += '\n ' + key.toString() + ': ' + pp(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return formatted;
|
return formatted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5849,8 +5845,8 @@ getJasmineRequireObj().ObjectPath = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function formatPropertyAccess(prop) {
|
function formatPropertyAccess(prop) {
|
||||||
if (typeof prop === 'number') {
|
if (typeof prop === 'number' || typeof prop === 'symbol') {
|
||||||
return '[' + prop + ']';
|
return '[' + prop.toString() + ']';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isValidIdentifier(prop)) {
|
if (isValidIdentifier(prop)) {
|
||||||
|
|||||||
@@ -196,10 +196,34 @@ describe('util', function() {
|
|||||||
quux: 7
|
quux: 7
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(jasmineUnderTest.util.objectDifference(a, b)).toEqual({
|
expect(jasmineUnderTest.util.objectDifference(a, b)).toEqual([
|
||||||
foo: 3,
|
['foo', 3],
|
||||||
baz: 5
|
['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() {
|
it('only looks at own properties of both objects', function() {
|
||||||
@@ -214,8 +238,8 @@ describe('util', function() {
|
|||||||
const b = new Foo();
|
const b = new Foo();
|
||||||
b.y = 2;
|
b.y = 2;
|
||||||
|
|
||||||
expect(jasmineUnderTest.util.objectDifference(a, b)).toEqual({ x: 1 });
|
expect(jasmineUnderTest.util.objectDifference(a, b)).toEqual([['x', 1]]);
|
||||||
expect(jasmineUnderTest.util.objectDifference(b, a)).toEqual({ y: 2 });
|
expect(jasmineUnderTest.util.objectDifference(b, a)).toEqual([['y', 2]]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ describe('ObjectPath', function() {
|
|||||||
expect(new ObjectPath(['1hello']).toString()).toEqual("$['1hello']");
|
expect(new ObjectPath(['1hello']).toString()).toEqual("$['1hello']");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('renders symbols with squre bracket notation', function() {
|
||||||
|
expect(new ObjectPath([Symbol('a')]).toString()).toEqual('$[Symbol(a)]');
|
||||||
|
});
|
||||||
|
|
||||||
it('renders as the empty string when empty', function() {
|
it('renders as the empty string when empty', function() {
|
||||||
expect(new ObjectPath().toString()).toEqual('');
|
expect(new ObjectPath().toString()).toEqual('');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -51,6 +51,15 @@ describe('toEqual', function() {
|
|||||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('reports differences between symbol properties', function() {
|
||||||
|
const x = Symbol('x'),
|
||||||
|
actual = { [x]: 1, y: 3 },
|
||||||
|
expected = { [x]: 2, y: 3 },
|
||||||
|
message = 'Expected $[Symbol(x)] = 1 to equal 2.';
|
||||||
|
|
||||||
|
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||||
|
});
|
||||||
|
|
||||||
it('reports the difference between nested objects that are not equal', function() {
|
it('reports the difference between nested objects that are not equal', function() {
|
||||||
const actual = { x: { y: 1 } },
|
const actual = { x: { y: 1 } },
|
||||||
expected = { x: { y: 2 } },
|
expected = { x: { y: 2 } },
|
||||||
@@ -75,6 +84,22 @@ describe('toEqual', function() {
|
|||||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('reports missing symbol properties', function() {
|
||||||
|
const actual = { x: {} },
|
||||||
|
expected = { x: { [Symbol('y')]: 1 } },
|
||||||
|
message = 'Expected $.x to have properties\n' + ' Symbol(y): 1';
|
||||||
|
|
||||||
|
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('reports extra symbol properties', function() {
|
||||||
|
const actual = { x: { [Symbol('y')]: 1 } },
|
||||||
|
expected = { x: {} },
|
||||||
|
message = 'Expected $.x not to have properties\n' + ' Symbol(y): 1';
|
||||||
|
|
||||||
|
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||||
|
});
|
||||||
|
|
||||||
it('reports extra properties', function() {
|
it('reports extra properties', function() {
|
||||||
const actual = { x: { y: 1, z: 2 } },
|
const actual = { x: { y: 1, z: 2 } },
|
||||||
expected = { x: {} },
|
expected = { x: {} },
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ getJasmineRequireObj().ObjectPath = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function formatPropertyAccess(prop) {
|
function formatPropertyAccess(prop) {
|
||||||
if (typeof prop === 'number') {
|
if (typeof prop === 'number' || typeof prop === 'symbol') {
|
||||||
return '[' + prop + ']';
|
return '[' + prop.toString() + ']';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isValidIdentifier(prop)) {
|
if (isValidIdentifier(prop)) {
|
||||||
|
|||||||
@@ -610,11 +610,13 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatKeyValuePairs(pp, obj) {
|
function formatKeyValuePairs(pp, keyValuePairs) {
|
||||||
var formatted = '';
|
let formatted = '';
|
||||||
for (var key in obj) {
|
|
||||||
formatted += '\n ' + key + ': ' + pp(obj[key]);
|
for (const [key, value] of keyValuePairs) {
|
||||||
|
formatted += '\n ' + key.toString() + ': ' + pp(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return formatted;
|
return formatted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,15 +76,9 @@ getJasmineRequireObj().util = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
util.objectDifference = function(obj, toRemove) {
|
util.objectDifference = function(obj, toRemove) {
|
||||||
var diff = {};
|
return j$.MatchersUtil.keys(obj)
|
||||||
|
.filter(key => !util.has(toRemove, key))
|
||||||
for (var key in obj) {
|
.map(key => [key, obj[key]]);
|
||||||
if (util.has(obj, key) && !util.has(toRemove, key)) {
|
|
||||||
diff[key] = obj[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return diff;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
util.has = function(obj, key) {
|
util.has = function(obj, key) {
|
||||||
|
|||||||
Reference in New Issue
Block a user