Made output of toHaveBeenCalledWith more readable
This breaks each call out onto its own line, so that it's much easier to
see where each call starts and how they differ. E.g. previously the output
would be:
Expected spy foo to have been called with [ 'bar', 'baz', 'qux' ] but actual calls were [ [ 42, 'wibble' ], [ 'bar' 'qux' ], [ 'grault '] ]
Now it's:
Expected spy foo to have been called with:
[ 'bar', 'baz', 'qux' ]
but actual calls were:
[ 42, 'wibble' ],
[ 'bar' 'qux' ],
[ 'grault '].
This commit is contained in:
@@ -5106,15 +5106,32 @@ getJasmineRequireObj().toHaveBeenCalledWith = function(j$) {
|
||||
}
|
||||
|
||||
if (!actual.calls.any()) {
|
||||
result.message = function() { return 'Expected spy ' + actual.and.identity + ' to have been called with ' + j$.pp(expectedArgs) + ' but it was never called.'; };
|
||||
result.message = function() {
|
||||
return 'Expected spy ' + actual.and.identity + ' to have been called with:\n' +
|
||||
' ' + j$.pp(expectedArgs) +
|
||||
'\nbut it was never called.';
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
if (util.contains(actual.calls.allArgs(), expectedArgs, customEqualityTesters)) {
|
||||
result.pass = true;
|
||||
result.message = function() { return 'Expected spy ' + actual.and.identity + ' not to have been called with ' + j$.pp(expectedArgs) + ' but it was.'; };
|
||||
result.message = function() {
|
||||
return 'Expected spy ' + actual.and.identity + ' not to have been called with:\n' +
|
||||
' ' + j$.pp(expectedArgs) +
|
||||
'\nbut it was.';
|
||||
};
|
||||
} else {
|
||||
result.message = function() { return 'Expected spy ' + actual.and.identity + ' to have been called with ' + j$.pp(expectedArgs) + ' but actual calls were ' + j$.pp(actual.calls.allArgs()).replace(/^\[ | \]$/g, '') + '.'; };
|
||||
result.message = function() {
|
||||
var prettyPrintedCalls = actual.calls.allArgs().map(function(argsForCall) {
|
||||
return ' ' + j$.pp(argsForCall);
|
||||
});
|
||||
|
||||
return 'Expected spy ' + actual.and.identity + ' to have been called with:\n' +
|
||||
' ' + j$.pp(expectedArgs) + '\n' + '' +
|
||||
'but actual calls were:\n' +
|
||||
prettyPrintedCalls.join(',\n') + '.';
|
||||
};
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -12,7 +12,7 @@ describe("toHaveBeenCalledWith", function() {
|
||||
result = matcher.compare(calledSpy, 'a', 'b');
|
||||
|
||||
expect(result.pass).toBe(true);
|
||||
expect(result.message()).toEqual("Expected spy called-spy not to have been called with [ 'a', 'b' ] but it was.");
|
||||
expect(result.message()).toEqual("Expected spy called-spy not to have been called with:\n [ 'a', 'b' ]\nbut it was.");
|
||||
});
|
||||
|
||||
it("passes through the custom equality testers", function() {
|
||||
@@ -39,7 +39,7 @@ describe("toHaveBeenCalledWith", function() {
|
||||
|
||||
result = matcher.compare(uncalledSpy);
|
||||
expect(result.pass).toBe(false);
|
||||
expect(result.message()).toEqual("Expected spy uncalled spy to have been called with [ ] but it was never called.");
|
||||
expect(result.message()).toEqual("Expected spy uncalled spy to have been called with:\n [ ]\nbut it was never called.");
|
||||
});
|
||||
|
||||
it("fails when the actual was called with different parameters", function() {
|
||||
@@ -55,7 +55,7 @@ describe("toHaveBeenCalledWith", function() {
|
||||
result = matcher.compare(calledSpy, 'a', 'b');
|
||||
|
||||
expect(result.pass).toBe(false);
|
||||
expect(result.message()).toEqual("Expected spy called spy to have been called with [ 'a', 'b' ] but actual calls were [ 'a' ], [ 'c', 'd' ].");
|
||||
expect(result.message()).toEqual("Expected spy called spy to have been called with:\n [ 'a', 'b' ]\nbut actual calls were:\n [ 'a' ],\n [ 'c', 'd' ].");
|
||||
});
|
||||
|
||||
it("throws an exception when the actual is not a spy", function() {
|
||||
|
||||
@@ -24,15 +24,32 @@ getJasmineRequireObj().toHaveBeenCalledWith = function(j$) {
|
||||
}
|
||||
|
||||
if (!actual.calls.any()) {
|
||||
result.message = function() { return 'Expected spy ' + actual.and.identity + ' to have been called with ' + j$.pp(expectedArgs) + ' but it was never called.'; };
|
||||
result.message = function() {
|
||||
return 'Expected spy ' + actual.and.identity + ' to have been called with:\n' +
|
||||
' ' + j$.pp(expectedArgs) +
|
||||
'\nbut it was never called.';
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
if (util.contains(actual.calls.allArgs(), expectedArgs, customEqualityTesters)) {
|
||||
result.pass = true;
|
||||
result.message = function() { return 'Expected spy ' + actual.and.identity + ' not to have been called with ' + j$.pp(expectedArgs) + ' but it was.'; };
|
||||
result.message = function() {
|
||||
return 'Expected spy ' + actual.and.identity + ' not to have been called with:\n' +
|
||||
' ' + j$.pp(expectedArgs) +
|
||||
'\nbut it was.';
|
||||
};
|
||||
} else {
|
||||
result.message = function() { return 'Expected spy ' + actual.and.identity + ' to have been called with ' + j$.pp(expectedArgs) + ' but actual calls were ' + j$.pp(actual.calls.allArgs()).replace(/^\[ | \]$/g, '') + '.'; };
|
||||
result.message = function() {
|
||||
var prettyPrintedCalls = actual.calls.allArgs().map(function(argsForCall) {
|
||||
return ' ' + j$.pp(argsForCall);
|
||||
});
|
||||
|
||||
return 'Expected spy ' + actual.and.identity + ' to have been called with:\n' +
|
||||
' ' + j$.pp(expectedArgs) + '\n' + '' +
|
||||
'but actual calls were:\n' +
|
||||
prettyPrintedCalls.join(',\n') + '.';
|
||||
};
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user