summaryrefslogtreecommitdiff
path: root/lib/assert.js
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2013-04-03 09:43:17 -0700
committerisaacs <i@izs.me>2013-04-03 09:52:56 -0700
commit4716dc662d8d24d4d454dd4459ff724588e98eb1 (patch)
treee94063d05e4ae4f03faa4951e3461685c56a967c /lib/assert.js
parent9f65b1edf7bffe8e99bd6ac2539336128e2f5900 (diff)
downloadnodejs-4716dc662d8d24d4d454dd4459ff724588e98eb1.tar.gz
nodejs-4716dc662d8d24d4d454dd4459ff724588e98eb1.tar.bz2
nodejs-4716dc662d8d24d4d454dd4459ff724588e98eb1.zip
assert: Simplify AssertError creation
Diffstat (limited to 'lib/assert.js')
-rw-r--r--lib/assert.js24
1 files changed, 10 insertions, 14 deletions
diff --git a/lib/assert.js b/lib/assert.js
index a2afdcfb0..078efe39c 100644
--- a/lib/assert.js
+++ b/lib/assert.js
@@ -38,16 +38,14 @@ var assert = module.exports = ok;
// expected: expected })
assert.AssertionError = function AssertionError(options) {
- this.name = 'AssertionError';
this.message = options.message;
this.actual = options.actual;
this.expected = options.expected;
this.operator = options.operator;
var stackStartFunction = options.stackStartFunction || fail;
- if (Error.captureStackTrace) {
- Error.captureStackTrace(this, stackStartFunction);
- }
+ this.name = getName(this, options.message);
+ Error.captureStackTrace(this, stackStartFunction);
};
// assert.AssertionError instanceof Error
@@ -74,18 +72,16 @@ function truncate(s, n) {
}
}
-assert.AssertionError.prototype.toString = function() {
- if (this.message) {
- return [this.name + ':', this.message].join(' ');
+function getName(self, message) {
+ if (message) {
+ return 'AssertionError: ' + message;
} else {
- return [
- this.name + ':',
- truncate(JSON.stringify(this.actual, replacer), 128),
- this.operator,
- truncate(JSON.stringify(this.expected, replacer), 128)
- ].join(' ');
+ return 'AssertionError: ' +
+ 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
// understood by the spec. Implementations or sub modules can pass