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.
51 lines
876 B
JavaScript
51 lines
876 B
JavaScript
getJasmineRequireObj().CallTracker = function() {
|
|
|
|
function CallTracker() {
|
|
var calls = [];
|
|
|
|
this.track = function(context) {
|
|
calls.push(context);
|
|
};
|
|
|
|
this.any = function() {
|
|
return !!calls.length;
|
|
};
|
|
|
|
this.count = function() {
|
|
return calls.length;
|
|
};
|
|
|
|
this.argsFor = function(index) {
|
|
var call = calls[index];
|
|
return call ? call.args : [];
|
|
};
|
|
|
|
this.all = function() {
|
|
return calls;
|
|
};
|
|
|
|
this.allArgs = function() {
|
|
var callArgs = [];
|
|
for(var i = 0; i < calls.length; i++){
|
|
callArgs.push(calls[i].args);
|
|
}
|
|
|
|
return callArgs;
|
|
};
|
|
|
|
this.first = function() {
|
|
return calls[0];
|
|
};
|
|
|
|
this.mostRecent = function() {
|
|
return calls[calls.length - 1];
|
|
};
|
|
|
|
this.reset = function() {
|
|
calls = [];
|
|
};
|
|
}
|
|
|
|
return CallTracker;
|
|
};
|