Skip to content

Commit

Permalink
test: check codes of thrown errors
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
truonghnancy authored and jasnell committed Oct 21, 2018
1 parent 52428c8 commit add4f01
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
16 changes: 10 additions & 6 deletions test/parallel/test-buffer-alloc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion test/parallel/test-buffer-arraybuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit add4f01

Please sign in to comment.