Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: check codes of thrown errors #23519

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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