summaryrefslogtreecommitdiff
path: root/test/parallel/test-internal-errors.js
diff options
context:
space:
mode:
authorDavidCai <davidcai1993@yahoo.com>2017-03-14 00:11:35 +0800
committerFranziska Hinkelmann <franzih@chromium.org>2017-03-15 17:09:33 +0100
commitb5eccc4c7eb634eabbc00ef0e72df6ce0b4c0377 (patch)
tree47f00f7c05f09e3a3bd22ebc7ab34b58b4038867 /test/parallel/test-internal-errors.js
parent5bd1642dd1797b6f1c016dfbaf6cf3c96075ac79 (diff)
downloadandroid-node-v8-b5eccc4c7eb634eabbc00ef0e72df6ce0b4c0377.tar.gz
android-node-v8-b5eccc4c7eb634eabbc00ef0e72df6ce0b4c0377.tar.bz2
android-node-v8-b5eccc4c7eb634eabbc00ef0e72df6ce0b4c0377.zip
lib, test: add duplicate symbol checking in E()
Add duplicate symbol checking in E() to avoid potential confusing result. Increase coverage of internal/errors. PR-URL: https://github.com/nodejs/node/pull/11829 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Diffstat (limited to 'test/parallel/test-internal-errors.js')
-rw-r--r--test/parallel/test-internal-errors.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/test/parallel/test-internal-errors.js b/test/parallel/test-internal-errors.js
index 354209fbad..014a0a7a03 100644
--- a/test/parallel/test-internal-errors.js
+++ b/test/parallel/test-internal-errors.js
@@ -12,6 +12,7 @@ const err1 = new errors.Error('TEST_ERROR_1', 'test');
const err2 = new errors.TypeError('TEST_ERROR_1', 'test');
const err3 = new errors.RangeError('TEST_ERROR_1', 'test');
const err4 = new errors.Error('TEST_ERROR_2', 'abc', 'xyz');
+const err5 = new errors.Error('TEST_ERROR_1');
assert(err1 instanceof Error);
assert.strictEqual(err1.name, 'Error[TEST_ERROR_1]');
@@ -33,6 +34,11 @@ assert.strictEqual(err4.name, 'Error[TEST_ERROR_2]');
assert.strictEqual(err4.message, 'abc xyz');
assert.strictEqual(err4.code, 'TEST_ERROR_2');
+assert(err5 instanceof Error);
+assert.strictEqual(err5.name, 'Error[TEST_ERROR_1]');
+assert.strictEqual(err5.message, 'Error for testing purposes: %s');
+assert.strictEqual(err5.code, 'TEST_ERROR_1');
+
assert.throws(
() => new errors.Error('TEST_FOO_KEY'),
/^AssertionError: An invalid error message key was used: TEST_FOO_KEY.$/);
@@ -118,3 +124,9 @@ assert.throws(() => {
type: TypeError,
message: /^Error for testing 2/ }));
}, /AssertionError: .+ does not match \S/);
+
+assert.doesNotThrow(() => errors.E('TEST_ERROR_USED_SYMBOL'));
+assert.throws(
+ () => errors.E('TEST_ERROR_USED_SYMBOL'),
+ /^AssertionError: Error symbol: TEST_ERROR_USED_SYMBOL was already used\.$/
+);