Allow adding custom spy strategies

[#37288941]
This commit is contained in:
Steve Gravrock
2018-01-10 08:41:47 -08:00
parent 1085914a76
commit 4934e420b2
7 changed files with 217 additions and 12 deletions

View File

@@ -16,6 +16,22 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
this.originalFn = options.fn || function() {};
this.getSpy = options.getSpy || function() {};
this.plan = this._defaultPlan = function() {};
var k, cs = options.customStrategies || {};
for (k in cs) {
if (j$.util.has(cs, k) && !this[k]) {
this[k] = function() {
var plan = cs[k].apply(null, arguments);
if (!j$.isFunction_(plan)) {
throw new Error('Spy strategy must return a function');
}
this.plan = plan;
return this.getSpy();
};
}
}
}
/**