diff --git a/doc/download/index.html b/doc/download/index.html index 5de4deaca0d..3d8f3feacd6 100644 --- a/doc/download/index.html +++ b/doc/download/index.html @@ -141,6 +141,7 @@
  • Other release files
  • Other releases
  • +
  • Nightly builds
  • diff --git a/lib/assert.js b/lib/assert.js index 078efe39c77..8b6b49ae43b 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 diff --git a/test/simple/test-assert.js b/test/simple/test-assert.js index 081eb76b653..2885858cf44 100644 --- a/test/simple/test-assert.js +++ b/test/simple/test-assert.js @@ -293,3 +293,16 @@ try { assert.equal(e.message, 'Missing expected exception..'); } assert.ok(threw); + +// #5292 +try { + assert.equal(1, 2); +} catch (e) { + assert.equal(e.toString().split('\n')[0], 'AssertionError: 1 == 2') +} + +try { + assert.equal(1, 2, 'oh no'); +} catch (e) { + assert.equal(e.toString().split('\n')[0], 'AssertionError: oh no') +}