Output a diff if there was only one call, but with wrong parameters
This commit is contained in:
@@ -49,7 +49,7 @@ describe("toHaveBeenCalledOnceWith", function () {
|
|||||||
result = matcher.compare(calledSpy, 'a', 'b');
|
result = matcher.compare(calledSpy, 'a', 'b');
|
||||||
|
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message).toEqual("Expected spy called-spy to have been called only once, and with given args:\n [ 'a', 'b' ]\nBut the actual calls were:\n [ 'a', 'c' ].\n\n");
|
expect(result.message).toEqual("Expected spy called-spy to have been called only once, and with given args:\n [ 'a', 'b' ]\nBut the actual call was:\n [ 'a', 'c' ].\nExpected $[1] = 'c' to equal 'b'.\n\n");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when the actual was called multiple times with expected parameters", function () {
|
it("fails when the actual was called multiple times with expected parameters", function () {
|
||||||
|
|||||||
@@ -36,10 +36,23 @@ getJasmineRequireObj().toHaveBeenCalledOnceWith = function (j$) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getDiffs() {
|
||||||
|
return actual.calls.allArgs().map(function (argsForCall, callIx) {
|
||||||
|
var diffBuilder = new j$.DiffBuilder();
|
||||||
|
util.equals(argsForCall, expectedArgs, customEqualityTesters, diffBuilder);
|
||||||
|
return diffBuilder.getMessage();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function butString() {
|
function butString() {
|
||||||
return actual.calls.count() !== 0
|
switch (actual.calls.count()) {
|
||||||
? 'But the actual calls were:\n' + prettyPrintedCalls.join(',\n') + '.\n\n'
|
case 0:
|
||||||
: 'But it was never called.\n\n';
|
return 'But it was never called.\n\n';
|
||||||
|
case 1:
|
||||||
|
return 'But the actual call was:\n' + prettyPrintedCalls.join(',\n') + '.\n' + getDiffs().join('\n') + '\n\n';
|
||||||
|
default:
|
||||||
|
return 'But the actual calls were:\n' + prettyPrintedCalls.join(',\n') + '.\n\n';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user