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:
committed by
Steve Gravrock
parent
dec67bd535
commit
1f23f1e4d2
@@ -309,12 +309,25 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
return 'suite' + nextSuiteId++;
|
||||
};
|
||||
|
||||
var makePrettyPrinter = function() {
|
||||
return j$.makePrettyPrinter();
|
||||
};
|
||||
|
||||
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: new j$.MatchersUtil({ customTesters: customEqualityTesters }),
|
||||
util: makeMatchersUtil(),
|
||||
customEqualityTesters: customEqualityTesters,
|
||||
customMatchers: runnableResources[spec.id].customMatchers,
|
||||
actual: actual,
|
||||
@@ -327,11 +340,8 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
};
|
||||
|
||||
var asyncExpectationFactory = function(actual, spec) {
|
||||
var customEqualityTesters =
|
||||
runnableResources[spec.id].customEqualityTesters;
|
||||
|
||||
return j$.Expectation.asyncFactory({
|
||||
util: new j$.MatchersUtil({ customTesters: customEqualityTesters }),
|
||||
util: makeMatchersUtil(),
|
||||
customEqualityTesters: runnableResources[spec.id].customEqualityTesters,
|
||||
customAsyncMatchers: runnableResources[spec.id].customAsyncMatchers,
|
||||
actual: actual,
|
||||
@@ -1143,7 +1153,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
message += error;
|
||||
} else {
|
||||
// pretty print all kind of objects. This includes arrays.
|
||||
message += j$.pp(error);
|
||||
message += makePrettyPrinter()(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ getJasmineRequireObj().Expectation = function(j$) {
|
||||
args = args.slice();
|
||||
args.unshift(true);
|
||||
args.unshift(matcherName);
|
||||
return util.buildFailureMessage.apply(null, args);
|
||||
return util.buildFailureMessage.apply(util, args);
|
||||
}
|
||||
|
||||
function negate(result) {
|
||||
|
||||
@@ -44,7 +44,7 @@ getJasmineRequireObj().Expector = function(j$) {
|
||||
var args = self.args.slice();
|
||||
args.unshift(false);
|
||||
args.unshift(self.matcherName);
|
||||
return self.util.buildFailureMessage.apply(null, args);
|
||||
return self.util.buildFailureMessage.apply(self.util, args);
|
||||
} else if (j$.isFunction_(result.message)) {
|
||||
return result.message();
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
getJasmineRequireObj().pp = function(j$) {
|
||||
function PrettyPrinter() {
|
||||
getJasmineRequireObj().makePrettyPrinter = function(j$) {
|
||||
function SinglePrettyPrintRun() {
|
||||
this.ppNestLevel_ = 0;
|
||||
this.seen = [];
|
||||
this.length = 0;
|
||||
@@ -21,7 +21,7 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
}
|
||||
}
|
||||
|
||||
PrettyPrinter.prototype.format = function(value) {
|
||||
SinglePrettyPrintRun.prototype.format = function(value) {
|
||||
this.ppNestLevel_++;
|
||||
try {
|
||||
if (j$.util.isUndefined(value)) {
|
||||
@@ -95,7 +95,7 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
}
|
||||
};
|
||||
|
||||
PrettyPrinter.prototype.iterateObject = function(obj, fn) {
|
||||
SinglePrettyPrintRun.prototype.iterateObject = function(obj, fn) {
|
||||
var objKeys = keys(obj, j$.isArray_(obj));
|
||||
var isGetter = function isGetter(prop) {};
|
||||
|
||||
@@ -114,15 +114,15 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
return objKeys.length > length;
|
||||
};
|
||||
|
||||
PrettyPrinter.prototype.emitScalar = function(value) {
|
||||
SinglePrettyPrintRun.prototype.emitScalar = function(value) {
|
||||
this.append(value);
|
||||
};
|
||||
|
||||
PrettyPrinter.prototype.emitString = function(value) {
|
||||
SinglePrettyPrintRun.prototype.emitString = function(value) {
|
||||
this.append("'" + value + "'");
|
||||
};
|
||||
|
||||
PrettyPrinter.prototype.emitArray = function(array) {
|
||||
SinglePrettyPrintRun.prototype.emitArray = function(array) {
|
||||
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
||||
this.append('Array');
|
||||
return;
|
||||
@@ -158,7 +158,7 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
this.append(' ]');
|
||||
};
|
||||
|
||||
PrettyPrinter.prototype.emitSet = function(set) {
|
||||
SinglePrettyPrintRun.prototype.emitSet = function(set) {
|
||||
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
||||
this.append('Set');
|
||||
return;
|
||||
@@ -183,7 +183,7 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
this.append(' )');
|
||||
};
|
||||
|
||||
PrettyPrinter.prototype.emitMap = function(map) {
|
||||
SinglePrettyPrintRun.prototype.emitMap = function(map) {
|
||||
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
||||
this.append('Map');
|
||||
return;
|
||||
@@ -208,7 +208,7 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
this.append(' )');
|
||||
};
|
||||
|
||||
PrettyPrinter.prototype.emitObject = function(obj) {
|
||||
SinglePrettyPrintRun.prototype.emitObject = function(obj) {
|
||||
var ctor = obj.constructor,
|
||||
constructorName;
|
||||
|
||||
@@ -244,7 +244,7 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
this.append(' })');
|
||||
};
|
||||
|
||||
PrettyPrinter.prototype.emitTypedArray = function(arr) {
|
||||
SinglePrettyPrintRun.prototype.emitTypedArray = function(arr) {
|
||||
var constructorName = j$.fnNameFor(arr.constructor),
|
||||
limitedArray = Array.prototype.slice.call(
|
||||
arr,
|
||||
@@ -260,7 +260,7 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
this.append(constructorName + ' [ ' + itemsString + ' ]');
|
||||
};
|
||||
|
||||
PrettyPrinter.prototype.emitDomElement = function(el) {
|
||||
SinglePrettyPrintRun.prototype.emitDomElement = function(el) {
|
||||
var tagName = el.tagName.toLowerCase(),
|
||||
attrs = el.attributes,
|
||||
i,
|
||||
@@ -286,7 +286,11 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
this.append(out);
|
||||
};
|
||||
|
||||
PrettyPrinter.prototype.formatProperty = function(obj, property, isGetter) {
|
||||
SinglePrettyPrintRun.prototype.formatProperty = function(
|
||||
obj,
|
||||
property,
|
||||
isGetter
|
||||
) {
|
||||
this.append(property);
|
||||
this.append(': ');
|
||||
if (isGetter) {
|
||||
@@ -296,7 +300,7 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
}
|
||||
};
|
||||
|
||||
PrettyPrinter.prototype.append = function(value) {
|
||||
SinglePrettyPrintRun.prototype.append = function(value) {
|
||||
// This check protects us from the rare case where an object has overriden
|
||||
// `toString()` with an invalid implementation (returning a non-string).
|
||||
if (typeof value !== 'string') {
|
||||
@@ -360,9 +364,12 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
|
||||
return extraKeys;
|
||||
}
|
||||
return function(value) {
|
||||
var prettyPrinter = new PrettyPrinter();
|
||||
prettyPrinter.format(value);
|
||||
return prettyPrinter.stringParts.join('');
|
||||
|
||||
return function() {
|
||||
return function(value) {
|
||||
var prettyPrinter = new SinglePrettyPrintRun();
|
||||
prettyPrinter.format(value);
|
||||
return prettyPrinter.stringParts.join('');
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -7,7 +7,10 @@ getJasmineRequireObj().Spy = function(j$) {
|
||||
};
|
||||
})();
|
||||
|
||||
var matchersUtil = new j$.MatchersUtil();
|
||||
var matchersUtil = new j$.MatchersUtil({
|
||||
customTesters: [],
|
||||
pp: j$.makePrettyPrinter()
|
||||
});
|
||||
|
||||
/**
|
||||
* _Note:_ Do not construct this directly, use {@link spyOn}, {@link spyOnProperty}, {@link jasmine.createSpy}, or {@link jasmine.createSpyObj}
|
||||
|
||||
@@ -11,7 +11,7 @@ getJasmineRequireObj().toBeRejectedWith = function(j$) {
|
||||
* @example
|
||||
* return expectAsync(aPromise).toBeRejectedWith({prop: 'value'});
|
||||
*/
|
||||
return function toBeRejectedWith(util) {
|
||||
return function toBeRejectedWith(matchersUtil) {
|
||||
return {
|
||||
compare: function(actualPromise, expectedValue) {
|
||||
if (!j$.isPromiseLike(actualPromise)) {
|
||||
@@ -21,7 +21,7 @@ getJasmineRequireObj().toBeRejectedWith = function(j$) {
|
||||
function prefix(passed) {
|
||||
return 'Expected a promise ' +
|
||||
(passed ? 'not ' : '') +
|
||||
'to be rejected with ' + j$.pp(expectedValue);
|
||||
'to be rejected with ' + matchersUtil.pp(expectedValue);
|
||||
}
|
||||
|
||||
return actualPromise.then(
|
||||
@@ -32,7 +32,7 @@ getJasmineRequireObj().toBeRejectedWith = function(j$) {
|
||||
};
|
||||
},
|
||||
function(actualValue) {
|
||||
if (util.equals(actualValue, expectedValue)) {
|
||||
if (matchersUtil.equals(actualValue, expectedValue)) {
|
||||
return {
|
||||
pass: true,
|
||||
message: prefix(true) + '.'
|
||||
@@ -40,7 +40,7 @@ getJasmineRequireObj().toBeRejectedWith = function(j$) {
|
||||
} else {
|
||||
return {
|
||||
pass: false,
|
||||
message: prefix(false) + ' but it was rejected with ' + j$.pp(actualValue) + '.'
|
||||
message: prefix(false) + ' but it was rejected with ' + matchersUtil.pp(actualValue) + '.'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,14 +14,14 @@ getJasmineRequireObj().toBeRejectedWithError = function(j$) {
|
||||
* await expectAsync(aPromise).toBeRejectedWithError('Error message');
|
||||
* return expectAsync(aPromise).toBeRejectedWithError(/Error message/);
|
||||
*/
|
||||
return function toBeRejectedWithError() {
|
||||
return function toBeRejectedWithError(matchersUtil) {
|
||||
return {
|
||||
compare: function(actualPromise, arg1, arg2) {
|
||||
if (!j$.isPromiseLike(actualPromise)) {
|
||||
throw new Error('Expected toBeRejectedWithError to be called on a promise.');
|
||||
}
|
||||
|
||||
var expected = getExpectedFromArgs(arg1, arg2);
|
||||
var expected = getExpectedFromArgs(arg1, arg2, matchersUtil);
|
||||
|
||||
return actualPromise.then(
|
||||
function() {
|
||||
@@ -30,15 +30,15 @@ getJasmineRequireObj().toBeRejectedWithError = function(j$) {
|
||||
message: 'Expected a promise to be rejected but it was resolved.'
|
||||
};
|
||||
},
|
||||
function(actualValue) { return matchError(actualValue, expected); }
|
||||
function(actualValue) { return matchError(actualValue, expected, matchersUtil); }
|
||||
);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
function matchError(actual, expected) {
|
||||
function matchError(actual, expected, matchersUtil) {
|
||||
if (!j$.isError_(actual)) {
|
||||
return fail(expected, 'rejected with ' + j$.pp(actual));
|
||||
return fail(expected, 'rejected with ' + matchersUtil.pp(actual));
|
||||
}
|
||||
|
||||
if (!(actual instanceof expected.error)) {
|
||||
@@ -55,7 +55,7 @@ getJasmineRequireObj().toBeRejectedWithError = function(j$) {
|
||||
return pass(expected);
|
||||
}
|
||||
|
||||
return fail(expected, 'rejected with ' + j$.pp(actual));
|
||||
return fail(expected, 'rejected with ' + matchersUtil.pp(actual));
|
||||
}
|
||||
|
||||
function pass(expected) {
|
||||
@@ -73,7 +73,7 @@ getJasmineRequireObj().toBeRejectedWithError = function(j$) {
|
||||
}
|
||||
|
||||
|
||||
function getExpectedFromArgs(arg1, arg2) {
|
||||
function getExpectedFromArgs(arg1, arg2, matchersUtil) {
|
||||
var error, message;
|
||||
|
||||
if (isErrorConstructor(arg1)) {
|
||||
@@ -87,7 +87,7 @@ getJasmineRequireObj().toBeRejectedWithError = function(j$) {
|
||||
return {
|
||||
error: error,
|
||||
message: message,
|
||||
printValue: j$.fnNameFor(error) + (typeof message === 'undefined' ? '' : ': ' + j$.pp(message))
|
||||
printValue: j$.fnNameFor(error) + (typeof message === 'undefined' ? '' : ': ' + matchersUtil.pp(message))
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ getJasmineRequireObj().toBeResolvedTo = function(j$) {
|
||||
* @example
|
||||
* return expectAsync(aPromise).toBeResolvedTo({prop: 'value'});
|
||||
*/
|
||||
return function toBeResolvedTo(util) {
|
||||
return function toBeResolvedTo(matchersUtil) {
|
||||
return {
|
||||
compare: function(actualPromise, expectedValue) {
|
||||
if (!j$.isPromiseLike(actualPromise)) {
|
||||
@@ -21,12 +21,12 @@ getJasmineRequireObj().toBeResolvedTo = function(j$) {
|
||||
function prefix(passed) {
|
||||
return 'Expected a promise ' +
|
||||
(passed ? 'not ' : '') +
|
||||
'to be resolved to ' + j$.pp(expectedValue);
|
||||
'to be resolved to ' + matchersUtil.pp(expectedValue);
|
||||
}
|
||||
|
||||
return actualPromise.then(
|
||||
function(actualValue) {
|
||||
if (util.equals(actualValue, expectedValue)) {
|
||||
if (matchersUtil.equals(actualValue, expectedValue)) {
|
||||
return {
|
||||
pass: true,
|
||||
message: prefix(true) + '.'
|
||||
@@ -34,7 +34,7 @@ getJasmineRequireObj().toBeResolvedTo = function(j$) {
|
||||
} else {
|
||||
return {
|
||||
pass: false,
|
||||
message: prefix(false) + ' but it was resolved to ' + j$.pp(actualValue) + '.'
|
||||
message: prefix(false) + ' but it was resolved to ' + matchersUtil.pp(actualValue) + '.'
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
getJasmineRequireObj().MatchersUtil = function(j$) {
|
||||
// TODO: what to do about jasmine.pp not being inject? move to JSON.stringify? gut PrettyPrinter?
|
||||
// TODO: convert all uses of j$.pp to use the injected pp
|
||||
|
||||
function MatchersUtil(options) {
|
||||
options = options || {};
|
||||
this.customTesters_ = options.customTesters || [];
|
||||
|
||||
if (!j$.isArray_(this.customTesters_)) {
|
||||
throw new Error("MatchersUtil requires custom equality testers");
|
||||
}
|
||||
}
|
||||
this.pp = options.pp || function() {};
|
||||
};
|
||||
|
||||
MatchersUtil.prototype.contains = function(haystack, needle, customTesters) {
|
||||
if (j$.isSet(haystack)) {
|
||||
@@ -30,6 +27,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
||||
};
|
||||
|
||||
MatchersUtil.prototype.buildFailureMessage = function() {
|
||||
var self = this;
|
||||
var args = Array.prototype.slice.call(arguments, 0),
|
||||
matcherName = args[0],
|
||||
isNot = args[1],
|
||||
@@ -38,7 +36,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
||||
englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); });
|
||||
|
||||
var message = 'Expected ' +
|
||||
j$.pp(actual) +
|
||||
self.pp(actual) +
|
||||
(isNot ? ' not ' : ' ') +
|
||||
englishyPredicate;
|
||||
|
||||
@@ -240,7 +238,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
||||
for (i = 0; i < aLength || i < bLength; i++) {
|
||||
diffBuilder.withPath(i, function() {
|
||||
if (i >= bLength) {
|
||||
diffBuilder.record(a[i], void 0, actualArrayIsLongerFormatter);
|
||||
diffBuilder.record(a[i], void 0, actualArrayIsLongerFormatter.bind(null, self.pp));
|
||||
result = false;
|
||||
} else {
|
||||
result = self.eq_(i < aLength ? a[i] : void 0, i < bLength ? b[i] : void 0, aStack, bStack, customTesters, diffBuilder) && result;
|
||||
@@ -357,7 +355,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
||||
a instanceof aCtor && b instanceof bCtor &&
|
||||
!(aCtor instanceof aCtor && bCtor instanceof bCtor)) {
|
||||
|
||||
diffBuilder.record(a, b, constructorsAreDifferentFormatter);
|
||||
diffBuilder.record(a, b, constructorsAreDifferentFormatter.bind(null, this.pp));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -368,7 +366,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
||||
|
||||
// Ensure that both objects contain the same number of properties before comparing deep equality.
|
||||
if (keys(b, className == '[object Array]').length !== size) {
|
||||
diffBuilder.record(a, b, objectKeysAreDifferentFormatter);
|
||||
diffBuilder.record(a, b, objectKeysAreDifferentFormatter.bind(null, this.pp));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -376,7 +374,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
||||
key = aKeys[i];
|
||||
// Deep compare each member
|
||||
if (!j$.util.has(b, key)) {
|
||||
diffBuilder.record(a, b, objectKeysAreDifferentFormatter);
|
||||
diffBuilder.record(a, b, objectKeysAreDifferentFormatter.bind(null, this.pp));
|
||||
result = false;
|
||||
continue;
|
||||
}
|
||||
@@ -433,11 +431,11 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
||||
return typeof obj === 'function';
|
||||
}
|
||||
|
||||
function objectKeysAreDifferentFormatter(actual, expected, path) {
|
||||
function objectKeysAreDifferentFormatter(pp, actual, expected, path) {
|
||||
var missingProperties = j$.util.objectDifference(expected, actual),
|
||||
extraProperties = j$.util.objectDifference(actual, expected),
|
||||
missingPropertiesMessage = formatKeyValuePairs(missingProperties),
|
||||
extraPropertiesMessage = formatKeyValuePairs(extraProperties),
|
||||
missingPropertiesMessage = formatKeyValuePairs(pp, missingProperties),
|
||||
extraPropertiesMessage = formatKeyValuePairs(pp, extraProperties),
|
||||
messages = [];
|
||||
|
||||
if (!path.depth()) {
|
||||
@@ -455,7 +453,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
||||
return messages.join('\n');
|
||||
}
|
||||
|
||||
function constructorsAreDifferentFormatter(actual, expected, path) {
|
||||
function constructorsAreDifferentFormatter(pp, actual, expected, path) {
|
||||
if (!path.depth()) {
|
||||
path = 'object';
|
||||
}
|
||||
@@ -463,20 +461,20 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
||||
return 'Expected ' +
|
||||
path + ' to be a kind of ' +
|
||||
j$.fnNameFor(expected.constructor) +
|
||||
', but was ' + j$.pp(actual) + '.';
|
||||
', but was ' + pp(actual) + '.';
|
||||
}
|
||||
|
||||
function actualArrayIsLongerFormatter(actual, expected, path) {
|
||||
function actualArrayIsLongerFormatter(pp, actual, expected, path) {
|
||||
return 'Unexpected ' +
|
||||
path + (path.depth() ? ' = ' : '') +
|
||||
j$.pp(actual) +
|
||||
pp(actual) +
|
||||
' in array.';
|
||||
}
|
||||
|
||||
function formatKeyValuePairs(obj) {
|
||||
function formatKeyValuePairs(pp, obj) {
|
||||
var formatted = '';
|
||||
for (var key in obj) {
|
||||
formatted += '\n ' + key + ': ' + j$.pp(obj[key]);
|
||||
formatted += '\n ' + key + ': ' + pp(obj[key]);
|
||||
}
|
||||
return formatted;
|
||||
}
|
||||
|
||||
@@ -12,11 +12,11 @@ getJasmineRequireObj().toBeInstanceOf = function(j$) {
|
||||
* expect(3).toBeInstanceOf(Number);
|
||||
* expect(new Error()).toBeInstanceOf(Error);
|
||||
*/
|
||||
function toBeInstanceOf() {
|
||||
function toBeInstanceOf(matchersUtil) {
|
||||
return {
|
||||
compare: function(actual, expected) {
|
||||
var actualType = actual && actual.constructor ? j$.fnNameFor(actual.constructor) : j$.pp(actual),
|
||||
expectedType = expected ? j$.fnNameFor(expected) : j$.pp(expected),
|
||||
var actualType = actual && actual.constructor ? j$.fnNameFor(actual.constructor) : matchersUtil.pp(actual),
|
||||
expectedType = expected ? j$.fnNameFor(expected) : matchersUtil.pp(expected),
|
||||
expectedMatcher,
|
||||
pass;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ getJasmineRequireObj().toBeNaN = function(j$) {
|
||||
* @example
|
||||
* expect(thing).toBeNaN();
|
||||
*/
|
||||
function toBeNaN() {
|
||||
function toBeNaN(matchersUtil) {
|
||||
return {
|
||||
compare: function(actual) {
|
||||
var result = {
|
||||
@@ -17,7 +17,7 @@ getJasmineRequireObj().toBeNaN = function(j$) {
|
||||
if (result.pass) {
|
||||
result.message = 'Expected actual not to be NaN.';
|
||||
} else {
|
||||
result.message = function() { return 'Expected ' + j$.pp(actual) + ' to be NaN.'; };
|
||||
result.message = function() { return 'Expected ' + matchersUtil.pp(actual) + ' to be NaN.'; };
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -7,7 +7,7 @@ getJasmineRequireObj().toBeNegativeInfinity = function(j$) {
|
||||
* @example
|
||||
* expect(thing).toBeNegativeInfinity();
|
||||
*/
|
||||
function toBeNegativeInfinity() {
|
||||
function toBeNegativeInfinity(matchersUtil) {
|
||||
return {
|
||||
compare: function(actual) {
|
||||
var result = {
|
||||
@@ -17,7 +17,7 @@ getJasmineRequireObj().toBeNegativeInfinity = function(j$) {
|
||||
if (result.pass) {
|
||||
result.message = 'Expected actual not to be -Infinity.';
|
||||
} else {
|
||||
result.message = function() { return 'Expected ' + j$.pp(actual) + ' to be -Infinity.'; };
|
||||
result.message = function() { return 'Expected ' + matchersUtil.pp(actual) + ' to be -Infinity.'; };
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -7,7 +7,7 @@ getJasmineRequireObj().toBePositiveInfinity = function(j$) {
|
||||
* @example
|
||||
* expect(thing).toBePositiveInfinity();
|
||||
*/
|
||||
function toBePositiveInfinity() {
|
||||
function toBePositiveInfinity(matchersUtil) {
|
||||
return {
|
||||
compare: function(actual) {
|
||||
var result = {
|
||||
@@ -17,7 +17,7 @@ getJasmineRequireObj().toBePositiveInfinity = function(j$) {
|
||||
if (result.pass) {
|
||||
result.message = 'Expected actual not to be Infinity.';
|
||||
} else {
|
||||
result.message = function() { return 'Expected ' + j$.pp(actual) + ' to be Infinity.'; };
|
||||
result.message = function() { return 'Expected ' + matchersUtil.pp(actual) + ' to be Infinity.'; };
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -11,13 +11,13 @@ getJasmineRequireObj().toHaveBeenCalled = function(j$) {
|
||||
* expect(mySpy).toHaveBeenCalled();
|
||||
* expect(mySpy).not.toHaveBeenCalled();
|
||||
*/
|
||||
function toHaveBeenCalled() {
|
||||
function toHaveBeenCalled(matchersUtil) {
|
||||
return {
|
||||
compare: function(actual) {
|
||||
var result = {};
|
||||
|
||||
if (!j$.isSpy(actual)) {
|
||||
throw new Error(getErrorMsg('Expected a spy, but got ' + j$.pp(actual) + '.'));
|
||||
throw new Error(getErrorMsg('Expected a spy, but got ' + matchersUtil.pp(actual) + '.'));
|
||||
}
|
||||
|
||||
if (arguments.length > 1) {
|
||||
|
||||
@@ -11,14 +11,14 @@ getJasmineRequireObj().toHaveBeenCalledBefore = function(j$) {
|
||||
* @example
|
||||
* expect(mySpy).toHaveBeenCalledBefore(otherSpy);
|
||||
*/
|
||||
function toHaveBeenCalledBefore() {
|
||||
function toHaveBeenCalledBefore(matchersUtil) {
|
||||
return {
|
||||
compare: function(firstSpy, latterSpy) {
|
||||
if (!j$.isSpy(firstSpy)) {
|
||||
throw new Error(getErrorMsg('Expected a spy, but got ' + j$.pp(firstSpy) + '.'));
|
||||
throw new Error(getErrorMsg('Expected a spy, but got ' + matchersUtil.pp(firstSpy) + '.'));
|
||||
}
|
||||
if (!j$.isSpy(latterSpy)) {
|
||||
throw new Error(getErrorMsg('Expected a spy, but got ' + j$.pp(latterSpy) + '.'));
|
||||
throw new Error(getErrorMsg('Expected a spy, but got ' + matchersUtil.pp(latterSpy) + '.'));
|
||||
}
|
||||
|
||||
var result = { pass: false };
|
||||
|
||||
@@ -11,11 +11,11 @@ getJasmineRequireObj().toHaveBeenCalledTimes = function(j$) {
|
||||
* @example
|
||||
* expect(mySpy).toHaveBeenCalledTimes(3);
|
||||
*/
|
||||
function toHaveBeenCalledTimes() {
|
||||
function toHaveBeenCalledTimes(matchersUtil) {
|
||||
return {
|
||||
compare: function(actual, expected) {
|
||||
if (!j$.isSpy(actual)) {
|
||||
throw new Error(getErrorMsg('Expected a spy, but got ' + j$.pp(actual) + '.'));
|
||||
throw new Error(getErrorMsg('Expected a spy, but got ' + matchersUtil.pp(actual) + '.'));
|
||||
}
|
||||
|
||||
var args = Array.prototype.slice.call(arguments, 0),
|
||||
|
||||
@@ -11,7 +11,7 @@ getJasmineRequireObj().toHaveBeenCalledWith = function(j$) {
|
||||
* @example
|
||||
* expect(mySpy).toHaveBeenCalledWith('foo', 'bar', 2);
|
||||
*/
|
||||
function toHaveBeenCalledWith(util) {
|
||||
function toHaveBeenCalledWith(matchersUtil) {
|
||||
return {
|
||||
compare: function() {
|
||||
var args = Array.prototype.slice.call(arguments, 0),
|
||||
@@ -20,40 +20,40 @@ getJasmineRequireObj().toHaveBeenCalledWith = function(j$) {
|
||||
result = { pass: false };
|
||||
|
||||
if (!j$.isSpy(actual)) {
|
||||
throw new Error(getErrorMsg('Expected a spy, but got ' + j$.pp(actual) + '.'));
|
||||
throw new Error(getErrorMsg('Expected a spy, but got ' + matchersUtil.pp(actual) + '.'));
|
||||
}
|
||||
|
||||
if (!actual.calls.any()) {
|
||||
result.message = function() {
|
||||
return 'Expected spy ' + actual.and.identity + ' to have been called with:\n' +
|
||||
' ' + j$.pp(expectedArgs) +
|
||||
' ' + matchersUtil.pp(expectedArgs) +
|
||||
'\nbut it was never called.';
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
if (util.contains(actual.calls.allArgs(), expectedArgs)) {
|
||||
if (matchersUtil.contains(actual.calls.allArgs(), expectedArgs)) {
|
||||
result.pass = true;
|
||||
result.message = function() {
|
||||
return 'Expected spy ' + actual.and.identity + ' not to have been called with:\n' +
|
||||
' ' + j$.pp(expectedArgs) +
|
||||
' ' + matchersUtil.pp(expectedArgs) +
|
||||
'\nbut it was.';
|
||||
};
|
||||
} else {
|
||||
result.message = function() {
|
||||
var prettyPrintedCalls = actual.calls.allArgs().map(function(argsForCall) {
|
||||
return ' ' + j$.pp(argsForCall);
|
||||
return ' ' + matchersUtil.pp(argsForCall);
|
||||
});
|
||||
|
||||
var diffs = actual.calls.allArgs().map(function(argsForCall, callIx) {
|
||||
var diffBuilder = new j$.DiffBuilder();
|
||||
util.equals(argsForCall, expectedArgs, diffBuilder);
|
||||
matchersUtil.equals(argsForCall, expectedArgs, diffBuilder);
|
||||
return 'Call ' + callIx + ':\n' +
|
||||
diffBuilder.getMessage().replace(/^/mg, ' ');
|
||||
});
|
||||
|
||||
return 'Expected spy ' + actual.and.identity + ' to have been called with:\n' +
|
||||
' ' + j$.pp(expectedArgs) + '\n' + '' +
|
||||
' ' + matchersUtil.pp(expectedArgs) + '\n' + '' +
|
||||
'but actual calls were:\n' +
|
||||
prettyPrintedCalls.join(',\n') + '.\n\n' +
|
||||
diffs.join('\n');
|
||||
|
||||
@@ -10,11 +10,11 @@ getJasmineRequireObj().toHaveClass = function(j$) {
|
||||
* el.className = 'foo bar baz';
|
||||
* expect(el).toHaveClass('bar');
|
||||
*/
|
||||
function toHaveClass() {
|
||||
function toHaveClass(matchersUtil) {
|
||||
return {
|
||||
compare: function(actual, expected) {
|
||||
if (!isElement(actual)) {
|
||||
throw new Error(j$.pp(actual) + ' is not a DOM element');
|
||||
throw new Error(matchersUtil.pp(actual) + ' is not a DOM element');
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -12,7 +12,7 @@ getJasmineRequireObj().toThrow = function(j$) {
|
||||
* expect(function() { return 'things'; }).toThrow('foo');
|
||||
* expect(function() { return 'stuff'; }).toThrow();
|
||||
*/
|
||||
function toThrow(util) {
|
||||
function toThrow(matchersUtil) {
|
||||
return {
|
||||
compare: function(actual, expected) {
|
||||
var result = { pass: false },
|
||||
@@ -37,16 +37,16 @@ getJasmineRequireObj().toThrow = function(j$) {
|
||||
|
||||
if (arguments.length == 1) {
|
||||
result.pass = true;
|
||||
result.message = function() { return 'Expected function not to throw, but it threw ' + j$.pp(thrown) + '.'; };
|
||||
result.message = function() { return 'Expected function not to throw, but it threw ' + matchersUtil.pp(thrown) + '.'; };
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
if (util.equals(thrown, expected)) {
|
||||
if (matchersUtil.equals(thrown, expected)) {
|
||||
result.pass = true;
|
||||
result.message = function() { return 'Expected function not to throw ' + j$.pp(expected) + '.'; };
|
||||
result.message = function() { return 'Expected function not to throw ' + matchersUtil.pp(expected) + '.'; };
|
||||
} else {
|
||||
result.message = function() { return 'Expected function to throw ' + j$.pp(expected) + ', but it threw ' + j$.pp(thrown) + '.'; };
|
||||
result.message = function() { return 'Expected function to throw ' + matchersUtil.pp(expected) + ', but it threw ' + matchersUtil.pp(thrown) + '.'; };
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ getJasmineRequireObj().toThrowMatching = function(j$) {
|
||||
* @example
|
||||
* expect(function() { throw new Error('nope'); }).toThrowMatching(function(thrown) { return thrown.message === 'nope'; });
|
||||
*/
|
||||
function toThrowMatching() {
|
||||
function toThrowMatching(matchersUtil) {
|
||||
return {
|
||||
compare: function(actual, predicate) {
|
||||
var thrown;
|
||||
@@ -40,14 +40,14 @@ getJasmineRequireObj().toThrowMatching = function(j$) {
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function thrownDescription(thrown) {
|
||||
if (thrown && thrown.constructor) {
|
||||
return j$.fnNameFor(thrown.constructor) + ' with message ' +
|
||||
j$.pp(thrown.message);
|
||||
} else {
|
||||
return j$.pp(thrown);
|
||||
function thrownDescription(thrown) {
|
||||
if (thrown && thrown.constructor) {
|
||||
return j$.fnNameFor(thrown.constructor) + ' with message ' +
|
||||
matchersUtil.pp(thrown.message);
|
||||
} else {
|
||||
return matchersUtil.pp(thrown);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,15 +54,19 @@ var getJasmineRequireObj = (function(jasmineGlobal) {
|
||||
j$.asymmetricEqualityTesterArgCompatShim = jRequire.asymmetricEqualityTesterArgCompatShim(
|
||||
j$
|
||||
);
|
||||
j$.makePrettyPrinter = jRequire.makePrettyPrinter(j$);
|
||||
j$.pp = j$.makePrettyPrinter();
|
||||
j$.MatchersUtil = jRequire.MatchersUtil(j$);
|
||||
j$.matchersUtil = new j$.MatchersUtil({ customTesters: [] });
|
||||
j$.matchersUtil = new j$.MatchersUtil({
|
||||
customTesters: [],
|
||||
pp: j$.pp
|
||||
});
|
||||
|
||||
j$.ObjectContaining = jRequire.ObjectContaining(j$);
|
||||
j$.ArrayContaining = jRequire.ArrayContaining(j$);
|
||||
j$.ArrayWithExactContents = jRequire.ArrayWithExactContents(j$);
|
||||
j$.MapContaining = jRequire.MapContaining(j$);
|
||||
j$.SetContaining = jRequire.SetContaining(j$);
|
||||
j$.pp = jRequire.pp(j$);
|
||||
j$.QueueRunner = jRequire.QueueRunner(j$);
|
||||
j$.ReportDispatcher = jRequire.ReportDispatcher(j$);
|
||||
j$.Spec = jRequire.Spec(j$);
|
||||
|
||||
Reference in New Issue
Block a user