Inject a per-runable pretty printer into MatchersUtil

This will allow us to add support for custom object formatters, which
will be a per-runable resource like custom matchers, by injecting them
into the pretty-printer.
This commit is contained in:
Steve Gravrock
2019-10-08 22:57:07 -07:00
committed by Steve Gravrock
parent dec67bd535
commit 1f23f1e4d2
46 changed files with 546 additions and 401 deletions

View File

@@ -16,7 +16,7 @@ getJasmineRequireObj().toThrowError = function(j$) {
* expect(function() { return 'other'; }).toThrowError(/foo/);
* expect(function() { return 'other'; }).toThrowError();
*/
function toThrowError () {
function toThrowError(matchersUtil) {
return {
compare: function(actual) {
var errorMatcher = getMatcher.apply(null, arguments),
@@ -34,7 +34,7 @@ getJasmineRequireObj().toThrowError = function(j$) {
}
if (!j$.isError_(thrown)) {
return fail(function() { return 'Expected function to throw an Error, but it threw ' + j$.pp(thrown) + '.'; });
return fail(function() { return 'Expected function to throw an Error, but it threw ' + matchersUtil.pp(thrown) + '.'; });
}
return errorMatcher.match(thrown);
@@ -97,7 +97,7 @@ getJasmineRequireObj().toThrowError = function(j$) {
thrownMessage = '';
if (expected) {
thrownMessage = ' with message ' + j$.pp(thrown.message);
thrownMessage = ' with message ' + matchersUtil.pp(thrown.message);
}
return thrownName + thrownMessage;
@@ -107,9 +107,9 @@ getJasmineRequireObj().toThrowError = function(j$) {
if (expected === null) {
return '';
} else if (expected instanceof RegExp) {
return ' with a message matching ' + j$.pp(expected);
return ' with a message matching ' + matchersUtil.pp(expected);
} else {
return ' with message ' + j$.pp(expected);
return ' with message ' + matchersUtil.pp(expected);
}
}