summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRyan Doenges <rhdoenges@gmail.com>2013-04-13 18:48:00 -0700
committerisaacs <i@izs.me>2013-04-18 15:08:35 -0700
commit6101eb184db77d0b11eb96e48744e57ecce4b73d (patch)
treefed10b1c4cbe55267169e99b7c458aa267cbbc5e /lib
parenta835a2fc47d55c95c03780a78af09f971637a351 (diff)
downloadandroid-node-v8-6101eb184db77d0b11eb96e48744e57ecce4b73d.tar.gz
android-node-v8-6101eb184db77d0b11eb96e48744e57ecce4b73d.tar.bz2
android-node-v8-6101eb184db77d0b11eb96e48744e57ecce4b73d.zip
assert: put info in err.message, not err.name
4716dc6 made assert.equal() and related functions work better by generating a better toString() from the expected, actual, and operator values passed to fail(). Unfortunately, this was accomplished by putting the generated message into the error's `name` property. When you passed in a custom error message, the error would put the custom error into `name` *and* `message`, resulting in helpful string representations like "AssertionError: Oh no: Oh no". This commit resolves that issue by storing the generated message in the `message` property while leaving the error's name alone and adding a regression test so that this doesn't pop back up later. Closes #5292.
Diffstat (limited to 'lib')
-rw-r--r--lib/assert.js18
1 files changed, 6 insertions, 12 deletions
diff --git a/lib/assert.js b/lib/assert.js
index 078efe39c7..8b6b49ae43 100644
--- a/lib/assert.js
+++ b/lib/assert.js
@@ -38,13 +38,12 @@ var assert = module.exports = ok;
// expected: expected })
assert.AssertionError = function AssertionError(options) {
- this.message = options.message;
+ this.name = 'AssertionError';
this.actual = options.actual;
this.expected = options.expected;
this.operator = options.operator;
+ this.message = options.message || getMessage(this)
var stackStartFunction = options.stackStartFunction || fail;
-
- this.name = getName(this, options.message);
Error.captureStackTrace(this, stackStartFunction);
};
@@ -72,15 +71,10 @@ function truncate(s, n) {
}
}
-function getName(self, message) {
- if (message) {
- return 'AssertionError: ' + message;
- } else {
- return 'AssertionError: ' +
- truncate(JSON.stringify(self.actual, replacer), 128) + ' ' +
- self.operator + ' ' +
- truncate(JSON.stringify(self.expected, replacer), 128);
- }
+function getMessage(self) {
+ return truncate(JSON.stringify(self.actual, replacer), 128) + ' ' +
+ self.operator + ' ' +
+ truncate(JSON.stringify(self.expected, replacer), 128);
}
// At present only the three keys mentioned above are used and