Add custom async matchers

This commit is contained in:
Tony Brix
2019-07-08 15:13:06 -05:00
committed by Steve Gravrock
parent 008b80adc5
commit f77ee32c56
18 changed files with 876 additions and 49 deletions

View File

@@ -266,6 +266,19 @@ getJasmineRequireObj().Env = function(j$) {
}
};
this.addAsyncMatchers = function(matchersToAdd) {
if (!currentRunnable()) {
throw new Error(
'Async Matchers must be added in a before function or a spec'
);
}
var customAsyncMatchers =
runnableResources[currentRunnable().id].customAsyncMatchers;
for (var matcherName in matchersToAdd) {
customAsyncMatchers[matcherName] = matchersToAdd[matcherName];
}
};
j$.Expectation.addCoreMatchers(j$.matchers);
j$.Expectation.addAsyncCoreMatchers(j$.asyncMatchers);
@@ -297,6 +310,7 @@ getJasmineRequireObj().Env = function(j$) {
return j$.Expectation.asyncFactory({
util: j$.matchersUtil,
customEqualityTesters: runnableResources[spec.id].customEqualityTesters,
customAsyncMatchers: runnableResources[spec.id].customAsyncMatchers,
actual: actual,
addExpectationResult: addExpectationResult
});
@@ -311,6 +325,7 @@ getJasmineRequireObj().Env = function(j$) {
spies: [],
customEqualityTesters: [],
customMatchers: {},
customAsyncMatchers: {},
customSpyStrategies: {},
defaultStrategyFn: undefined
};
@@ -322,6 +337,9 @@ getJasmineRequireObj().Env = function(j$) {
resources.customMatchers = j$.util.clone(
runnableResources[parentRunnableId].customMatchers
);
resources.customAsyncMatchers = j$.util.clone(
runnableResources[parentRunnableId].customAsyncMatchers
);
resources.defaultStrategyFn =
runnableResources[parentRunnableId].defaultStrategyFn;
}