Squashed spy refactor and new spy syntax
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.
This commit is contained in:
committed by
Colin O'Byrne and JR Boyens
parent
18c30566bd
commit
3847557bbc
45
src/core/SpyStrategy.js
Normal file
45
src/core/SpyStrategy.js
Normal file
@@ -0,0 +1,45 @@
|
||||
getJasmineRequireObj().SpyStrategy = function() {
|
||||
|
||||
function SpyStrategy(options) {
|
||||
options = options || {};
|
||||
|
||||
var identity = options.name || "unknown",
|
||||
originalFn = options.fn || function() {},
|
||||
getSpy = options.getSpy || function() {},
|
||||
plan = function() {};
|
||||
|
||||
this.identity = function() {
|
||||
return identity;
|
||||
};
|
||||
|
||||
this.exec = function() {
|
||||
return plan.apply(this, arguments);
|
||||
};
|
||||
|
||||
this.callThrough = function() {
|
||||
plan = originalFn;
|
||||
return getSpy();
|
||||
};
|
||||
|
||||
this.callReturn = function(value) {
|
||||
plan = function() {
|
||||
return value;
|
||||
};
|
||||
return getSpy();
|
||||
};
|
||||
|
||||
this.callThrow = function(something) {
|
||||
plan = function() {
|
||||
throw something;
|
||||
};
|
||||
return getSpy();
|
||||
};
|
||||
|
||||
this.callFake = function(fn) {
|
||||
plan = fn;
|
||||
return getSpy();
|
||||
};
|
||||
}
|
||||
|
||||
return SpyStrategy;
|
||||
};
|
||||
Reference in New Issue
Block a user