diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2018-09-24 13:09:27 +0200 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-09-27 13:25:17 +0200 |
commit | be26c761146db8357653df345e505a624b2153da (patch) | |
tree | 9ef85c98eebc8ff0e0a9595da65b3ceef538fd67 /test | |
parent | a58f37720d389fe921b35daf45afb1c4e2c02274 (diff) | |
download | android-node-v8-be26c761146db8357653df345e505a624b2153da.tar.gz android-node-v8-be26c761146db8357653df345e505a624b2153da.tar.bz2 android-node-v8-be26c761146db8357653df345e505a624b2153da.zip |
assert: improve the strict equal messages
In case reference (un)equal objects fail in assertion, it should be
clear that it is about the reference equality and not about the
object properties. This is fixed by improving the message in such
cases.
Refs: https://github.com/nodejs/node/issues/22763
PR-URL: https://github.com/nodejs/node/pull/23056
Refs: https://github.com/nodejs/node/issues/22763
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-assert.js | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index ed6af5310f..883ebea1a2 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -415,9 +415,9 @@ assert.throws( { code: 'ERR_ASSERTION', name: 'AssertionError [ERR_ASSERTION]', - message: strictEqualMessageStart + + message: 'Expected "actual" to be reference-equal to "expected":\n' + '+ actual - expected\n\n' + - '+ [Error: foo]\n- [Error: foobar]\n ^' + '+ [Error: foo]\n- [Error: foobar]' } ); @@ -1022,7 +1022,8 @@ assert.throws( assert.throws( () => assert.strictEqual(args, { 0: 'a' }), { - message: `${strictEqualMessageStart}+ actual - expected\n\n` + + message: 'Expected "actual" to be reference-equal to "expected":\n' + + '+ actual - expected\n\n' + "+ [Arguments] {\n- {\n '0': 'a'\n }" } ); @@ -1091,3 +1092,43 @@ assert.throws( } ); } + +// Indicate where the strings diverge. +assert.throws( + () => assert.strictEqual('test test', 'test foobar'), + { + code: 'ERR_ASSERTION', + name: 'AssertionError [ERR_ASSERTION]', + message: strictEqualMessageStart + + '+ actual - expected\n\n' + + "+ 'test test'\n" + + "- 'test foobar'\n" + + ' ^' + } +); + +// Check for reference equal objects in `notStrictEqual()` +assert.throws( + () => { + const obj = {}; + assert.notStrictEqual(obj, obj); + }, + { + code: 'ERR_ASSERTION', + name: 'AssertionError [ERR_ASSERTION]', + message: 'Expected "actual" not to be reference-equal to "expected": {}' + } +); + +assert.throws( + () => { + const obj = { a: true }; + assert.notStrictEqual(obj, obj); + }, + { + code: 'ERR_ASSERTION', + name: 'AssertionError [ERR_ASSERTION]', + message: 'Expected "actual" not to be reference-equal to "expected":\n\n' + + '{\n a: true\n}\n' + } +); |