Output a diff if there was only one call, but with wrong parameters

This commit is contained in:
Maksym Kobieliev
2020-04-02 21:31:17 +03:00
parent e13fd13529
commit bcc28d7063
2 changed files with 17 additions and 4 deletions

View File

@@ -49,7 +49,7 @@ describe("toHaveBeenCalledOnceWith", function () {
result = matcher.compare(calledSpy, 'a', 'b');
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 () {

View File

@@ -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() {
return actual.calls.count() !== 0
? 'But the actual calls were:\n' + prettyPrintedCalls.join(',\n') + '.\n\n'
: 'But it was never called.\n\n';
switch (actual.calls.count()) {
case 0:
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 {