Merge branch 'custom-object-formatters' into cof-merge-candidate

This commit is contained in:
Steve Gravrock
2020-02-11 11:44:38 -08:00
84 changed files with 3047 additions and 1017 deletions

View File

@@ -276,6 +276,7 @@ getJasmineRequireObj().Env = function(j$) {
}
var customMatchers =
runnableResources[currentRunnable().id].customMatchers;
for (var matcherName in matchersToAdd) {
customMatchers[matcherName] = matchersToAdd[matcherName];
}
@@ -289,11 +290,24 @@ getJasmineRequireObj().Env = function(j$) {
}
var customAsyncMatchers =
runnableResources[currentRunnable().id].customAsyncMatchers;
for (var matcherName in matchersToAdd) {
customAsyncMatchers[matcherName] = matchersToAdd[matcherName];
}
};
this.addCustomObjectFormatter = function(formatter) {
if (!currentRunnable()) {
throw new Error(
'Custom object formatters must be added in a before function or a spec'
);
}
runnableResources[currentRunnable().id].customObjectFormatters.push(
formatter
);
};
j$.Expectation.addCoreMatchers(j$.matchers);
j$.Expectation.addAsyncCoreMatchers(j$.asyncMatchers);
@@ -307,10 +321,28 @@ getJasmineRequireObj().Env = function(j$) {
return 'suite' + nextSuiteId++;
};
var makePrettyPrinter = function() {
var customObjectFormatters =
runnableResources[currentRunnable().id].customObjectFormatters;
return j$.makePrettyPrinter(customObjectFormatters);
};
var makeMatchersUtil = function() {
var customEqualityTesters =
runnableResources[currentRunnable().id].customEqualityTesters;
return new j$.MatchersUtil({
customTesters: customEqualityTesters,
pp: makePrettyPrinter()
});
};
var expectationFactory = function(actual, spec) {
var customEqualityTesters =
runnableResources[spec.id].customEqualityTesters;
return j$.Expectation.factory({
util: j$.matchersUtil,
customEqualityTesters: runnableResources[spec.id].customEqualityTesters,
matchersUtil: makeMatchersUtil(),
customEqualityTesters: customEqualityTesters,
customMatchers: runnableResources[spec.id].customMatchers,
actual: actual,
addExpectationResult: addExpectationResult
@@ -349,7 +381,7 @@ getJasmineRequireObj().Env = function(j$) {
var asyncExpectationFactory = function(actual, spec, runableType) {
return j$.Expectation.asyncFactory({
util: j$.matchersUtil,
matchersUtil: makeMatchersUtil(),
customEqualityTesters: runnableResources[spec.id].customEqualityTesters,
customAsyncMatchers: runnableResources[spec.id].customAsyncMatchers,
actual: actual,
@@ -378,7 +410,8 @@ getJasmineRequireObj().Env = function(j$) {
customMatchers: {},
customAsyncMatchers: {},
customSpyStrategies: {},
defaultStrategyFn: undefined
defaultStrategyFn: undefined,
customObjectFormatters: []
};
if (runnableResources[parentRunnableId]) {
@@ -1171,7 +1204,7 @@ getJasmineRequireObj().Env = function(j$) {
message += error;
} else {
// pretty print all kind of objects. This includes arrays.
message += j$.pp(error);
message += makePrettyPrinter()(error);
}
}