Provide better diffs for object graphs that include objectContaining
Turns this output:
Expected $[0].foo = Object({ a: 4, b: 5 }) to equal <jasmine.objectContaining(Object({ a: 1, c: 3 }))>.
into this:
Expected $[0].foo.a = 4 to equal 1.
Expected $[0].foo.c = undefined to equal 3.
And turns this output:
Expected spy jasmineDone to have been called with:
[ ... snipped very long expected call ]
but actual calls were:
[ ... snipped very long actual call ]
Call 0:
Expected $[0] = Object({ overallStatus: 'failed', totalTime: 1, incompleteReason: undefined, order: Order({ random: true, seed: '88732', sort: Function }), failedExpectations: [ Object({ matcherName: 'toBeResolved', passed: false, message: 'Suite "a suite" ran a "toBeResolved" expectation after it finished.
Did you forget to return or await the result of expectAsync?', error: undefined, errorForStack: Error, actual: [object Promise], expected: [ ], globalErrorType: 'lateExpeztation' }) ], deprecationWarnings: [ ] }) to equal <jasmine.objectContaining(Object({ failedExpectations: [ <jasmine.objectContaining(Object({ passed: false, globalErrorType: 'lateExpectation', message: 'Suite "a suite" ran a "toBeResolved" expectation after it finished.
Did you forget to return or await the result of expectAsync?', matcherName: 'toBeResolved' }))> ] }))>.
into this:
Expected spy jasmineDone to have been called with:
[ ... snipped very long expected call ]
but actual calls were:
[ ... snipped very long actual call ]
Call 0:
Expected $[0].failedExpectations[0].globalErrorType = 'lateExpeztation' to equal 'lateExpectation'.
This commit is contained in:
@@ -593,6 +593,42 @@ describe("matchersUtil", function() {
|
||||
expect(['foo']).toEqual(['foo']);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Building diffs for asymmetric equality testers", function() {
|
||||
it("diffs the values returned by valuesForDiff_", function() {
|
||||
var tester = {
|
||||
asymmetricMatch: function() { return false; },
|
||||
valuesForDiff_: function() {
|
||||
return {
|
||||
self: 'asymmetric tester value',
|
||||
other: 'other value'
|
||||
}
|
||||
}
|
||||
},
|
||||
diffBuilder = jasmine.createSpyObj('diffBuilder', ['record', 'withPath']);
|
||||
diffBuilder.withPath.and.callFake(function(p, block) { block() });
|
||||
debugger;
|
||||
jasmineUnderTest.matchersUtil.equals({x: 42}, {x: tester}, [], diffBuilder);
|
||||
|
||||
expect(diffBuilder.withPath).toHaveBeenCalledWith('x', jasmine.any(Function));
|
||||
expect(diffBuilder.record). toHaveBeenCalledWith(
|
||||
'other value', 'asymmetric tester value'
|
||||
);
|
||||
});
|
||||
|
||||
it("records both objects when the tester does not implement valuesForDiff", function() {
|
||||
var tester = {
|
||||
asymmetricMatch: function() { return false; },
|
||||
},
|
||||
diffBuilder = jasmine.createSpyObj('diffBuilder', ['record', 'withPath']);
|
||||
diffBuilder.withPath.and.callFake(function(p, block) { block() });
|
||||
debugger;
|
||||
jasmineUnderTest.matchersUtil.equals({x: 42}, {x: tester}, [], diffBuilder);
|
||||
|
||||
expect(diffBuilder.withPath).toHaveBeenCalledWith('x', jasmine.any(Function));
|
||||
expect(diffBuilder.record). toHaveBeenCalledWith(42, tester);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("contains", function() {
|
||||
|
||||
@@ -350,6 +350,20 @@ describe("toEqual", function() {
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("reports mismatches involving objectContaining", 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 a non-object and objectContaining", function() {
|
||||
var actual = {x: 1};
|
||||
var expected = {x: jasmineUnderTest.objectContaining({a: 1})};
|
||||
expect(compareEquals(actual, expected).message).toEqual(
|
||||
"Expected $.x = 1 to equal '<jasmine.objectContaining(Object({ a: 1 }))>'."
|
||||
);
|
||||
});
|
||||
|
||||
// == Sets ==
|
||||
|
||||
it("reports mismatches between Sets", function() {
|
||||
|
||||
Reference in New Issue
Block a user