Don't clobber previous custom plans with later plans

[finishes #37288941]
This commit is contained in:
Gregg Van Hove
2018-01-22 12:10:24 -08:00
parent 170a6dce76
commit f20f78f82b
8 changed files with 109 additions and 35 deletions

View File

@@ -20,20 +20,24 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
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();
};
this[k] = createCustomPlan(cs[k]);
}
}
}
function createCustomPlan(factory) {
return function() {
var plan = factory.apply(null, arguments);
if (!j$.isFunction_(plan)) {
throw new Error('Spy strategy must return a function');
}
this.plan = plan;
return this.getSpy();
};
}
/**
* Execute the current spy strategy.
* @name SpyStrategy#exec