diff options
author | kpdecker <kpdecker@gmail.com> | 2015-08-14 15:20:09 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2015-08-14 15:20:09 -0500 |
commit | 624a4c71aa3ec2206e2338d939c0ae8df7eec97a (patch) | |
tree | 117043345bc76b484e32bc606d6d7055a8c8ad2c | |
parent | 3ce04ddd23fe92796a6581b3de10658d9e7ac3c6 (diff) | |
download | handlebars.js-624a4c71aa3ec2206e2338d939c0ae8df7eec97a.zip handlebars.js-624a4c71aa3ec2206e2338d939c0ae8df7eec97a.tar.gz handlebars.js-624a4c71aa3ec2206e2338d939c0ae8df7eec97a.tar.bz2 |
Cleanup stack traces for test assertions
-rw-r--r-- | spec/env/common.js | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/spec/env/common.js b/spec/env/common.js index e4c8ae5..f2c9dc6 100644 --- a/spec/env/common.js +++ b/spec/env/common.js @@ -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); } }; |