Cleanup stack traces for test assertions
This commit is contained in:
Vendored
+22
-6
@@ -1,11 +1,27 @@
|
||||
var AssertError;
|
||||
if (Error.captureStackTrace) {
|
||||
AssertError = function AssertError(message, caller) {
|
||||
Error.prototype.constructor.call(this, message);
|
||||
this.message = message;
|
||||
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, caller || AssertError);
|
||||
}
|
||||
};
|
||||
|
||||
AssertError.prototype = new Error();
|
||||
} else {
|
||||
AssertError = Error;
|
||||
}
|
||||
|
||||
global.shouldCompileTo = function(string, hashOrArray, expected, message) {
|
||||
shouldCompileToWithPartials(string, hashOrArray, false, expected, message);
|
||||
};
|
||||
|
||||
global.shouldCompileToWithPartials = function(string, hashOrArray, partials, expected, message) {
|
||||
global.shouldCompileToWithPartials = function shouldCompileToWithPartials(string, hashOrArray, partials, expected, message) {
|
||||
var result = compileWithPartials(string, hashOrArray, partials);
|
||||
if (result !== expected) {
|
||||
throw new Error("'" + result + "' should === '" + expected + "': " + message);
|
||||
throw new AssertError("'" + result + "' should === '" + expected + "': " + message, shouldCompileToWithPartials);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -31,9 +47,9 @@ global.compileWithPartials = function(string, hashOrArray, partials) {
|
||||
};
|
||||
|
||||
|
||||
global.equals = global.equal = function(a, b, msg) {
|
||||
global.equals = global.equal = function equals(a, b, msg) {
|
||||
if (a !== b) {
|
||||
throw new Error("'" + a + "' should === '" + b + "'" + (msg ? ': ' + msg : ''));
|
||||
throw new AssertError("'" + a + "' should === '" + b + "'" + (msg ? ': ' + msg : ''), equals);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -44,13 +60,13 @@ global.shouldThrow = function(callback, type, msg) {
|
||||
failed = true;
|
||||
} catch (err) {
|
||||
if (type && !(err instanceof type)) {
|
||||
throw new Error('Type failure: ' + err);
|
||||
throw new AssertError('Type failure: ' + err);
|
||||
}
|
||||
if (msg && !(msg.test ? msg.test(err.message) : msg === err.message)) {
|
||||
equal(msg, err.message);
|
||||
}
|
||||
}
|
||||
if (failed) {
|
||||
throw new Error('It failed to throw');
|
||||
throw new AssertError('It failed to throw', shouldThrow);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user