Skip to content

Commit add4f01

Browse files
truonghnancyjasnell
authored andcommitted
test: check codes of thrown errors
PR-URL: #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>
1 parent 52428c8 commit add4f01

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

test/parallel/test-buffer-alloc.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -967,12 +967,16 @@ common.expectsError(
967967
message: 'argument must be a buffer'
968968
});
969969

970-
const regErrorMsg =
971-
new RegExp('The first argument must be one of type string, Buffer, ' +
972-
'ArrayBuffer, Array, or Array-like Object\\.');
973-
974-
assert.throws(() => Buffer.from(), regErrorMsg);
975-
assert.throws(() => Buffer.from(null), regErrorMsg);
970+
assert.throws(() => Buffer.from(), {
971+
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
972+
message: 'The first argument must be one of type string, Buffer, ' +
973+
'ArrayBuffer, Array, or Array-like Object. Received type undefined'
974+
});
975+
assert.throws(() => Buffer.from(null), {
976+
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
977+
message: 'The first argument must be one of type string, Buffer, ' +
978+
'ArrayBuffer, Array, or Array-like Object. Received type object'
979+
});
976980

977981
// Test prototype getters don't throw
978982
assert.strictEqual(Buffer.prototype.parent, undefined);

test/parallel/test-buffer-arraybuffer.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ assert.throws(function() {
4040
Object.setPrototypeOf(AB, ArrayBuffer);
4141
Object.setPrototypeOf(AB.prototype, ArrayBuffer.prototype);
4242
Buffer.from(new AB());
43-
}, TypeError);
43+
}, {
44+
code: 'ERR_INVALID_ARG_TYPE',
45+
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
46+
message: 'The first argument must be one of type string, Buffer,' +
47+
' ArrayBuffer, Array, or Array-like Object. Received type object'
48+
});
4449

4550
// Test the byteOffset and length arguments
4651
{

0 commit comments

Comments
 (0)