Show diffs involving root-level asymmetric equality testers
* Fixes #1831
This commit is contained in:
@@ -149,7 +149,7 @@ describe("ObjectContaining", function() {
|
||||
});
|
||||
});
|
||||
|
||||
it("includes keys that are present in only sample", function() {
|
||||
it("includes keys that are present only in sample", function() {
|
||||
var sample = {a: 1, b: 2},
|
||||
other = {a: 3},
|
||||
containing = new jasmineUnderTest.ObjectContaining(sample),
|
||||
|
||||
@@ -133,4 +133,50 @@ describe("DiffBuilder", function () {
|
||||
|
||||
expect(diffBuilder.getMessage()).toEqual(expectedMsg);
|
||||
});
|
||||
|
||||
it('builds diffs involving asymmetric equality testers that implement valuesForDiff_ at the root', function() {
|
||||
var prettyPrinter = jasmineUnderTest.makePrettyPrinter([]),
|
||||
diffBuilder = new jasmineUnderTest.DiffBuilder({prettyPrinter: prettyPrinter}),
|
||||
expectedMsg = 'Expected $.foo = 1 to equal 2.\n' +
|
||||
"Expected $.baz = undefined to equal 3.";
|
||||
|
||||
|
||||
diffBuilder.setRoots(
|
||||
{foo: 1, bar: 2},
|
||||
jasmine.objectContaining({foo: 2, baz: 3})
|
||||
);
|
||||
|
||||
diffBuilder.withPath('foo', function() {
|
||||
diffBuilder.recordMismatch();
|
||||
});
|
||||
diffBuilder.withPath('baz', function() {
|
||||
diffBuilder.recordMismatch();
|
||||
});
|
||||
|
||||
expect(diffBuilder.getMessage()).toEqual(expectedMsg);
|
||||
});
|
||||
|
||||
it('builds diffs involving asymmetric equality testers that implement valuesForDiff_ below the root', function() {
|
||||
var prettyPrinter = jasmineUnderTest.makePrettyPrinter([]),
|
||||
diffBuilder = new jasmineUnderTest.DiffBuilder({prettyPrinter: prettyPrinter}),
|
||||
expectedMsg = 'Expected $.x.foo = 1 to equal 2.\n' +
|
||||
"Expected $.x.baz = undefined to equal 3.";
|
||||
|
||||
|
||||
diffBuilder.setRoots(
|
||||
{x: {foo: 1, bar: 2}},
|
||||
{x: jasmine.objectContaining({foo: 2, baz: 3})}
|
||||
);
|
||||
|
||||
diffBuilder.withPath('x', function() {
|
||||
diffBuilder.withPath('foo', function () {
|
||||
diffBuilder.recordMismatch();
|
||||
});
|
||||
diffBuilder.withPath('baz', function () {
|
||||
diffBuilder.recordMismatch();
|
||||
});
|
||||
});
|
||||
|
||||
expect(diffBuilder.getMessage()).toEqual(expectedMsg);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -429,17 +429,30 @@ describe("toEqual", function() {
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("reports mismatches involving objectContaining and an object", function() {
|
||||
var actual = {x: {a: 1, b: 4, c: 3, extra: 'ignored'}};
|
||||
var expected = {x: jasmineUnderTest.objectContaining({a: 1, b: 2, c: 3})};
|
||||
expect(compareEquals(actual, expected).message).toEqual('Expected $.x.b = 4 to equal 2.');
|
||||
it('reports mismatches between an object and objectContaining', function() {
|
||||
var actual = {a: 1, b: 4, c: 3, extra: 'ignored'};
|
||||
var expected = jasmineUnderTest.objectContaining({a: 1, b: 2, c: 3, d: 4});
|
||||
expect(compareEquals(actual, expected).message)
|
||||
.toEqual(
|
||||
'Expected $.b = 4 to equal 2.\n' +
|
||||
'Expected $.d = undefined to equal 4.'
|
||||
);
|
||||
});
|
||||
|
||||
it("reports mismatches between a non-object and objectContaining", function() {
|
||||
var actual = {x: 1};
|
||||
var expected = {x: jasmineUnderTest.objectContaining({a: 1})};
|
||||
var actual = 1;
|
||||
var expected = jasmineUnderTest.objectContaining({a: 1});
|
||||
expect(compareEquals(actual, expected).message).toEqual(
|
||||
"Expected $.x = 1 to equal '<jasmine.objectContaining(Object({ a: 1 }))>'."
|
||||
"Expected 1 to equal '<jasmine.objectContaining(Object({ a: 1 }))>'."
|
||||
);
|
||||
});
|
||||
|
||||
it("reports mismatches involving a nested objectContaining", function() {
|
||||
var actual = {x: {a: 1, b: 4, c: 3, extra: 'ignored'}};
|
||||
var expected = {x: jasmineUnderTest.objectContaining({a: 1, b: 2, c: 3, d: 4})};
|
||||
expect(compareEquals(actual, expected).message).toEqual(
|
||||
'Expected $.x.b = 4 to equal 2.\n' +
|
||||
'Expected $.x.d = undefined to equal 4.'
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user