summaryrefslogtreecommitdiff
path: root/test/parallel/test-assert.js
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/parallel/test-assert.js
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/parallel/test-assert.js')
-rw-r--r--test/parallel/test-assert.js24
1 files changed, 16 insertions, 8 deletions
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 });