test: check codes of thrown errors

PR-URL: https://github.com/nodejs/node/pull/23519
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: George Adams <george.adams@uk.ibm.com>
This commit is contained in:
Nancy Truong 2018-10-12 10:23:36 -07:00 committed by Rich Trott
parent e7af9830e9
commit c208135055
2 changed files with 16 additions and 7 deletions

View File

@ -967,12 +967,16 @@ common.expectsError(
message: 'argument must be a buffer' message: 'argument must be a buffer'
}); });
const regErrorMsg = assert.throws(() => Buffer.from(), {
new RegExp('The first argument must be one of type string, Buffer, ' + name: 'TypeError [ERR_INVALID_ARG_TYPE]',
'ArrayBuffer, Array, or Array-like Object\\.'); message: 'The first argument must be one of type string, Buffer, ' +
'ArrayBuffer, Array, or Array-like Object. Received type undefined'
assert.throws(() => Buffer.from(), regErrorMsg); });
assert.throws(() => Buffer.from(null), regErrorMsg); assert.throws(() => Buffer.from(null), {
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
message: 'The first argument must be one of type string, Buffer, ' +
'ArrayBuffer, Array, or Array-like Object. Received type object'
});
// Test prototype getters don't throw // Test prototype getters don't throw
assert.strictEqual(Buffer.prototype.parent, undefined); assert.strictEqual(Buffer.prototype.parent, undefined);

View File

@ -40,7 +40,12 @@ assert.throws(function() {
Object.setPrototypeOf(AB, ArrayBuffer); Object.setPrototypeOf(AB, ArrayBuffer);
Object.setPrototypeOf(AB.prototype, ArrayBuffer.prototype); Object.setPrototypeOf(AB.prototype, ArrayBuffer.prototype);
Buffer.from(new AB()); Buffer.from(new AB());
}, TypeError); }, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
message: 'The first argument must be one of type string, Buffer,' +
' ArrayBuffer, Array, or Array-like Object. Received type object'
});
// Test the byteOffset and length arguments // Test the byteOffset and length arguments
{ {