Allow users to set a default spy strategy
This commit is contained in:
@@ -208,6 +208,13 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
}
|
||||
});
|
||||
|
||||
this.setDefaultSpyStrategy = function(defaultStrategyFn) {
|
||||
if (!currentRunnable()) {
|
||||
throw new Error('Default spy strategy must be set in a before function or a spec');
|
||||
}
|
||||
runnableResources[currentRunnable().id].defaultStrategyFn = defaultStrategyFn;
|
||||
};
|
||||
|
||||
this.addSpyStrategy = function(name, fn) {
|
||||
if (!currentRunnable()) {
|
||||
throw new Error(
|
||||
@@ -286,7 +293,8 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
spies: [],
|
||||
customEqualityTesters: [],
|
||||
customMatchers: {},
|
||||
customSpyStrategies: {}
|
||||
customSpyStrategies: {},
|
||||
defaultStrategyFn: undefined
|
||||
};
|
||||
|
||||
if (runnableResources[parentRunnableId]) {
|
||||
@@ -296,6 +304,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
resources.customMatchers = j$.util.clone(
|
||||
runnableResources[parentRunnableId].customMatchers
|
||||
);
|
||||
resources.defaultStrategyFn = runnableResources[parentRunnableId].defaultStrategyFn;
|
||||
}
|
||||
|
||||
runnableResources[id] = resources;
|
||||
@@ -720,6 +729,15 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
|
||||
return {};
|
||||
},
|
||||
function getDefaultStrategyFn() {
|
||||
var runnable = currentRunnable();
|
||||
|
||||
if (runnable) {
|
||||
return runnableResources[runnable.id].defaultStrategyFn;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
},
|
||||
function getPromise() {
|
||||
return customPromise || global.Promise;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user