errors,test: migrating error to internal/errors

PR-URL: https://github.com/nodejs/node/pull/11505
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
larissayvette 2017-02-21 17:43:26 +01:00 committed by Rich Trott
parent d74a545535
commit 1c834e78ff
2 changed files with 39 additions and 31 deletions

View File

@ -513,7 +513,9 @@ function _throws(shouldThrow, block, expected, message) {
var actual; var actual;
if (typeof block !== 'function') { if (typeof block !== 'function') {
throw new TypeError('"block" argument must be a function'); const errors = lazyErrors();
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'block', 'function',
typeof block);
} }
if (typeof expected === 'string') { if (typeof expected === 'string') {

View File

@ -655,39 +655,45 @@ try {
'Message incorrectly marked as generated'); 'Message incorrectly marked as generated');
} }
// Verify that throws() and doesNotThrow() throw on non-function block {
function testBlockTypeError(method, block) { // Verify that throws() and doesNotThrow() throw on non-function block
const validationFunction = common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError
});
const testBlockTypeError = (method, block) => {
let threw = true; let threw = true;
try { try {
method(block); method(block);
threw = false; threw = false;
} catch (e) { } catch (e) {
assert.strictEqual(e.toString(), validationFunction(e);
'TypeError: "block" argument must be a function');
} }
assert.ok(threw); assert.ok(threw);
} };
testBlockTypeError(assert.throws, 'string'); testBlockTypeError(assert.throws, 'string');
testBlockTypeError(assert.doesNotThrow, 'string'); testBlockTypeError(assert.doesNotThrow, 'string');
testBlockTypeError(assert.throws, 1); testBlockTypeError(assert.throws, 1);
testBlockTypeError(assert.doesNotThrow, 1); testBlockTypeError(assert.doesNotThrow, 1);
testBlockTypeError(assert.throws, true); testBlockTypeError(assert.throws, true);
testBlockTypeError(assert.doesNotThrow, true); testBlockTypeError(assert.doesNotThrow, true);
testBlockTypeError(assert.throws, false); testBlockTypeError(assert.throws, false);
testBlockTypeError(assert.doesNotThrow, false); testBlockTypeError(assert.doesNotThrow, false);
testBlockTypeError(assert.throws, []); testBlockTypeError(assert.throws, []);
testBlockTypeError(assert.doesNotThrow, []); testBlockTypeError(assert.doesNotThrow, []);
testBlockTypeError(assert.throws, {}); testBlockTypeError(assert.throws, {});
testBlockTypeError(assert.doesNotThrow, {}); testBlockTypeError(assert.doesNotThrow, {});
testBlockTypeError(assert.throws, /foo/); testBlockTypeError(assert.throws, /foo/);
testBlockTypeError(assert.doesNotThrow, /foo/); testBlockTypeError(assert.doesNotThrow, /foo/);
testBlockTypeError(assert.throws, null); testBlockTypeError(assert.throws, null);
testBlockTypeError(assert.doesNotThrow, null); testBlockTypeError(assert.doesNotThrow, null);
testBlockTypeError(assert.throws, undefined); testBlockTypeError(assert.throws, undefined);
testBlockTypeError(assert.doesNotThrow, undefined); testBlockTypeError(assert.doesNotThrow, undefined);
}
// https://github.com/nodejs/node/issues/3275 // https://github.com/nodejs/node/issues/3275
// eslint-disable-next-line no-throw-literal // eslint-disable-next-line no-throw-literal