summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2019-05-01 23:52:37 +0200
committerRich Trott <rtrott@gmail.com>2019-05-05 14:44:19 -0700
commit0cd602879c5e3f6a77adc2453f98b331421b2dbb (patch)
tree096b07b6a98cf974f3fff03f608c64f0c108d16b /test
parent3593af00f8e2748a4e36ef425051d7d04b5e5bb0 (diff)
downloadandroid-node-v8-0cd602879c5e3f6a77adc2453f98b331421b2dbb.tar.gz
android-node-v8-0cd602879c5e3f6a77adc2453f98b331421b2dbb.tar.bz2
android-node-v8-0cd602879c5e3f6a77adc2453f98b331421b2dbb.zip
assert: refine assertion message
This makes sure that the error message is more appropriate than before by checking closer what operator is used and which is not. It also increases the total number of lines printed to the user. PR-URL: https://github.com/nodejs/node/pull/27525 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-assert-deep.js28
-rw-r--r--test/parallel/test-assert.js24
-rw-r--r--test/pseudo-tty/test-assert-position-indicator.js2
3 files changed, 38 insertions, 16 deletions
diff --git a/test/parallel/test-assert-deep.js b/test/parallel/test-assert-deep.js
index 3675a18a28..013c47121b 100644
--- a/test/parallel/test-assert-deep.js
+++ b/test/parallel/test-assert-deep.js
@@ -195,7 +195,7 @@ function assertDeepAndStrictEqual(a, b) {
function assertNotDeepOrStrict(a, b, err) {
assert.throws(
() => assert.deepEqual(a, b),
- err || re`${a}\n\nshould equal\n\n${b}`
+ err || re`${a}\n\nshould loosely deep-equal\n\n${b}`
);
assert.throws(
() => assert.deepStrictEqual(a, b),
@@ -204,7 +204,7 @@ function assertNotDeepOrStrict(a, b, err) {
assert.throws(
() => assert.deepEqual(b, a),
- err || re`${b}\n\nshould equal\n\n${a}`
+ err || re`${b}\n\nshould loosely deep-equal\n\n${a}`
);
assert.throws(
() => assert.deepStrictEqual(b, a),
@@ -651,6 +651,20 @@ assertDeepAndStrictEqual(-0, -0);
assertDeepAndStrictEqual(a, b);
}
+assert.throws(
+ () => assert.notDeepEqual(1, true),
+ {
+ message: /1\n\nshould not loosely deep-equal\n\ntrue/
+ }
+);
+
+assert.throws(
+ () => assert.notDeepEqual(1, 1),
+ {
+ message: /Expected "actual" not to be loosely deep-equal to:\n\n1/
+ }
+);
+
assert.deepEqual(new Date(2000, 3, 14), new Date(2000, 3, 14));
assert.throws(() => { assert.deepEqual(new Date(), new Date(2000, 3, 14)); },
@@ -779,7 +793,7 @@ assert.throws(
() => assert.notDeepStrictEqual(new Date(2000, 3, 14), new Date(2000, 3, 14)),
{
name: 'AssertionError',
- message: 'Expected "actual" not to be strictly deep-equal to: ' +
+ message: 'Expected "actual" not to be strictly deep-equal to:\n\n' +
util.inspect(new Date(2000, 3, 14))
}
);
@@ -815,11 +829,11 @@ assert.throws(
message: `${defaultMsgStartFull}\n\n+ /a/m\n- /a/`
});
assert.throws(
- () => assert.deepStrictEqual(/a/igm, /a/im),
+ () => assert.deepStrictEqual(/aa/igm, /aa/im),
{
code: 'ERR_ASSERTION',
name: 'AssertionError',
- message: `${defaultMsgStartFull}\n\n+ /a/gim\n- /a/im\n ^`
+ message: `${defaultMsgStartFull}\n\n+ /aa/gim\n- /aa/im\n ^`
});
{
@@ -939,12 +953,12 @@ assert.deepStrictEqual(obj1, obj2);
}
// Strict equal with identical objects that are not identical
-// by reference and longer than 30 elements
+// by reference and longer than 50 elements
// E.g., assert.deepStrictEqual({ a: Symbol() }, { a: Symbol() })
{
const a = {};
const b = {};
- for (let i = 0; i < 35; i++) {
+ for (let i = 0; i < 55; i++) {
a[`symbol${i}`] = Symbol();
b[`symbol${i}`] = Symbol();
}
diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js
index 98f728acfa..b7d81f5495 100644
--- a/test/parallel/test-assert.js
+++ b/test/parallel/test-assert.js
@@ -80,12 +80,20 @@ assert.throws(
assert.throws(
() => a.notStrictEqual('a '.repeat(30), 'a '.repeat(30)),
{
- message: 'Expected "actual" to be strictly unequal to: ' +
+ message: 'Expected "actual" to be strictly unequal to:\n\n' +
`'${'a '.repeat(30)}'`,
name: 'AssertionError'
}
);
+assert.throws(
+ () => a.notEqual(1, 1),
+ {
+ message: '1 != 1',
+ operator: '!='
+ }
+);
+
a.notStrictEqual(2, '2');
// Testing the throwing.
@@ -281,12 +289,12 @@ testShortAssertionMessage('a', '"a"');
testShortAssertionMessage('foo', '\'foo\'');
testShortAssertionMessage(0, '0');
testShortAssertionMessage(Symbol(), 'Symbol()');
+testShortAssertionMessage(undefined, 'undefined');
+testShortAssertionMessage(-Infinity, '-Infinity');
testAssertionMessage([], '[]');
testAssertionMessage(/a/, '/a/');
testAssertionMessage(/abc/gim, '/abc/gim');
testAssertionMessage({}, '{}');
-testAssertionMessage(undefined, 'undefined');
-testAssertionMessage(-Infinity, '-Infinity');
testAssertionMessage([1, 2, 3], '[\n+ 1,\n+ 2,\n+ 3\n+ ]');
testAssertionMessage(function f() {}, '[Function: f]');
testAssertionMessage(function() {}, '[Function (anonymous)]');
@@ -579,12 +587,12 @@ assert.throws(
`${actExp} ... Lines skipped\n` +
'\n' +
' [\n' +
- '+ 1,\n'.repeat(10) +
+ '+ 1,\n'.repeat(25) +
'...\n' +
- '- 2,\n'.repeat(10) +
+ '- 2,\n'.repeat(25) +
'...';
assert.throws(
- () => assert.deepEqual(Array(12).fill(1), Array(12).fill(2)),
+ () => assert.deepEqual(Array(28).fill(1), Array(28).fill(2)),
{ message });
const obj1 = {};
@@ -612,8 +620,8 @@ assert.throws(
);
message = 'Expected "actual" not to be strictly deep-equal to:' +
- `\n\n[${'\n 1,'.repeat(25)}\n...\n`;
- const data = Array(31).fill(1);
+ `\n\n[${'\n 1,'.repeat(45)}\n...\n`;
+ const data = Array(51).fill(1);
assert.throws(
() => assert.notDeepEqual(data, data),
{ message });
diff --git a/test/pseudo-tty/test-assert-position-indicator.js b/test/pseudo-tty/test-assert-position-indicator.js
index 26f82b5b13..e56299d274 100644
--- a/test/pseudo-tty/test-assert-position-indicator.js
+++ b/test/pseudo-tty/test-assert-position-indicator.js
@@ -13,6 +13,6 @@ assert.throws(
// Confirm that there is a position indicator.
assert.throws(
- () => { assert.deepStrictEqual('aaa', 'aaaa'); },
+ () => { assert.deepStrictEqual('aaaa', 'aaaaa'); },
(err) => err.message.includes('^')
);