summaryrefslogtreecommitdiff
path: root/test/parallel/test-assert-checktag.js
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-03-12 22:14:24 +0100
committerJames M Snell <jasnell@gmail.com>2018-04-14 10:43:43 -0700
commitbfe54df81240151a3aeaf99dcd91c362bab3a6b0 (patch)
tree2a78d0195295c23e21ae181eaf70174bd731c3d1 /test/parallel/test-assert-checktag.js
parentf2d112c6b7e81263de7ff911fa189a336d863892 (diff)
downloadandroid-node-v8-bfe54df81240151a3aeaf99dcd91c362bab3a6b0.tar.gz
android-node-v8-bfe54df81240151a3aeaf99dcd91c362bab3a6b0.tar.bz2
android-node-v8-bfe54df81240151a3aeaf99dcd91c362bab3a6b0.zip
assert: improve default error messages
This improves the error messages for: - assert.notDeepStrictEqual - assert.deepStrictEqual - assert.notStrictEqual - assert.strictEqual Those will now always use the same error message as used in the strict mode. PR-URL: https://github.com/nodejs/node/pull/19467 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-assert-checktag.js')
-rw-r--r--test/parallel/test-assert-checktag.js38
1 files changed, 15 insertions, 23 deletions
diff --git a/test/parallel/test-assert-checktag.js b/test/parallel/test-assert-checktag.js
index 632bfa03c6..38ebaa1a14 100644
--- a/test/parallel/test-assert-checktag.js
+++ b/test/parallel/test-assert-checktag.js
@@ -1,24 +1,6 @@
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
-const util = require('util');
-
-// Template tag function turning an error message into a RegExp
-// for assert.throws()
-function re(literals, ...values) {
- let result = literals[0];
- const escapeRE = /[\\^$.*+?()[\]{}|=!<>:-]/g;
- for (const [i, value] of values.entries()) {
- const str = util.inspect(value);
- // Need to escape special characters.
- result += str.replace(escapeRE, '\\$&');
- result += literals[i + 1];
- }
- return common.expectsError({
- code: 'ERR_ASSERTION',
- message: new RegExp(`^${result}$`)
- });
-}
// Turn off no-restricted-properties because we are testing deepEqual!
/* eslint-disable no-restricted-properties */
@@ -35,10 +17,20 @@ function re(literals, ...values) {
// For deepStrictEqual we check the runtime type,
// then reveal the fakeness of the fake date
- assert.throws(() => assert.deepStrictEqual(date, fake),
- re`${date} deepStrictEqual Date {}`);
- assert.throws(() => assert.deepStrictEqual(fake, date),
- re`Date {} deepStrictEqual ${date}`);
+ assert.throws(
+ () => assert.deepStrictEqual(date, fake),
+ {
+ message: 'Input A expected to strictly deep-equal input B:\n' +
+ '+ expected - actual\n\n- 2016-01-01T00:00:00.000Z\n+ Date {}'
+ }
+ );
+ assert.throws(
+ () => assert.deepStrictEqual(fake, date),
+ {
+ message: 'Input A expected to strictly deep-equal input B:\n' +
+ '+ expected - actual\n\n- Date {}\n+ 2016-01-01T00:00:00.000Z'
+ }
+ );
}
{ // At the moment global has its own type tag