@@ -196,10 +196,34 @@ describe('util', function() {
|
||||
quux: 7
|
||||
};
|
||||
|
||||
expect(jasmineUnderTest.util.objectDifference(a, b)).toEqual({
|
||||
foo: 3,
|
||||
baz: 5
|
||||
});
|
||||
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() {
|
||||
@@ -214,8 +238,8 @@ describe('util', function() {
|
||||
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 });
|
||||
expect(jasmineUnderTest.util.objectDifference(a, b)).toEqual([['x', 1]]);
|
||||
expect(jasmineUnderTest.util.objectDifference(b, a)).toEqual([['y', 2]]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -25,6 +25,10 @@ describe('ObjectPath', function() {
|
||||
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() {
|
||||
expect(new ObjectPath().toString()).toEqual('');
|
||||
});
|
||||
|
||||
@@ -51,6 +51,15 @@ describe('toEqual', function() {
|
||||
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() {
|
||||
const actual = { x: { y: 1 } },
|
||||
expected = { x: { y: 2 } },
|
||||
@@ -75,6 +84,22 @@ describe('toEqual', function() {
|
||||
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() {
|
||||
const actual = { x: { y: 1, z: 2 } },
|
||||
expected = { x: {} },
|
||||
|
||||
Reference in New Issue
Block a user