Skip to content

Commit

Permalink
test: refactor test-internal-errors
Browse files Browse the repository at this point in the history
Use block-scoping rather than `err1`, `err2`, etc.

PR-URL: #15721
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
Trott authored and MylesBorins committed Oct 11, 2017
1 parent df1d988 commit 3f12109
Showing 1 changed file with 39 additions and 30 deletions.
69 changes: 39 additions & 30 deletions test/parallel/test-internal-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,45 @@ function invalidKey(key) {
errors.E('TEST_ERROR_1', 'Error for testing purposes: %s');
errors.E('TEST_ERROR_2', (a, b) => `${a} ${b}`);

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]');
assert.strictEqual(err1.message, 'Error for testing purposes: test');
assert.strictEqual(err1.code, 'TEST_ERROR_1');

assert(err2 instanceof TypeError);
assert.strictEqual(err2.name, 'TypeError [TEST_ERROR_1]');
assert.strictEqual(err2.message, 'Error for testing purposes: test');
assert.strictEqual(err2.code, 'TEST_ERROR_1');

assert(err3 instanceof RangeError);
assert.strictEqual(err3.name, 'RangeError [TEST_ERROR_1]');
assert.strictEqual(err3.message, 'Error for testing purposes: test');
assert.strictEqual(err3.code, 'TEST_ERROR_1');

assert(err4 instanceof Error);
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');
{
const err = new errors.Error('TEST_ERROR_1', 'test');
assert(err instanceof Error);
assert.strictEqual(err.name, 'Error [TEST_ERROR_1]');
assert.strictEqual(err.message, 'Error for testing purposes: test');
assert.strictEqual(err.code, 'TEST_ERROR_1');
}

{
const err = new errors.TypeError('TEST_ERROR_1', 'test');
assert(err instanceof TypeError);
assert.strictEqual(err.name, 'TypeError [TEST_ERROR_1]');
assert.strictEqual(err.message, 'Error for testing purposes: test');
assert.strictEqual(err.code, 'TEST_ERROR_1');
}

{
const err = new errors.RangeError('TEST_ERROR_1', 'test');
assert(err instanceof RangeError);
assert.strictEqual(err.name, 'RangeError [TEST_ERROR_1]');
assert.strictEqual(err.message, 'Error for testing purposes: test');
assert.strictEqual(err.code, 'TEST_ERROR_1');
}

{
const err = new errors.Error('TEST_ERROR_2', 'abc', 'xyz');
assert(err instanceof Error);
assert.strictEqual(err.name, 'Error [TEST_ERROR_2]');
assert.strictEqual(err.message, 'abc xyz');
assert.strictEqual(err.code, 'TEST_ERROR_2');
}

{
const err = new errors.Error('TEST_ERROR_1');
assert(err instanceof Error);
assert.strictEqual(err.name, 'Error [TEST_ERROR_1]');
assert.strictEqual(err.message, 'Error for testing purposes: %s');
assert.strictEqual(err.code, 'TEST_ERROR_1');
}

assert.throws(
() => new errors.Error('TEST_FOO_KEY'),
Expand Down

0 comments on commit 3f12109

Please sign in to comment.