Jasmine spies now have a 'and' property which allows the user to change the spy's execution strategy-- such as '.and.callReturn(4)' and a 'calls' property which allows inspection of the calls a spy has received. * This is a breaking change * There is a CallTracker that keeps track of all calls and arguments and a SpyStrategy which determines what the spy should do when it is called.
29 lines
743 B
JavaScript
29 lines
743 B
JavaScript
getJasmineRequireObj().toHaveBeenCalled = function(j$) {
|
|
|
|
function toHaveBeenCalled() {
|
|
return {
|
|
compare: function(actual) {
|
|
var result = {};
|
|
|
|
if (!j$.isSpy(actual)) {
|
|
throw new Error('Expected a spy, but got ' + j$.pp(actual) + '.');
|
|
}
|
|
|
|
if (arguments.length > 1) {
|
|
throw new Error('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith');
|
|
}
|
|
|
|
result.pass = actual.calls.any();
|
|
|
|
result.message = result.pass ?
|
|
"Expected spy " + actual.and.identity() + " not to have been called." :
|
|
"Expected spy " + actual.and.identity() + " to have been called.";
|
|
|
|
return result;
|
|
}
|
|
};
|
|
}
|
|
|
|
return toHaveBeenCalled;
|
|
};
|