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:
parent
e7af9830e9
commit
c208135055
@ -967,12 +967,16 @@ common.expectsError(
|
||||
message: 'argument must be a buffer'
|
||||
});
|
||||
|
||||
const regErrorMsg =
|
||||
new RegExp('The first argument must be one of type string, Buffer, ' +
|
||||
'ArrayBuffer, Array, or Array-like Object\\.');
|
||||
|
||||
assert.throws(() => Buffer.from(), regErrorMsg);
|
||||
assert.throws(() => Buffer.from(null), regErrorMsg);
|
||||
assert.throws(() => Buffer.from(), {
|
||||
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 undefined'
|
||||
});
|
||||
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
|
||||
assert.strictEqual(Buffer.prototype.parent, undefined);
|
||||
|
@ -40,7 +40,12 @@ assert.throws(function() {
|
||||
Object.setPrototypeOf(AB, ArrayBuffer);
|
||||
Object.setPrototypeOf(AB.prototype, ArrayBuffer.prototype);
|
||||
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
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user