mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
test: refactor common.expectsError
This completely refactors the `expectsError` behavior: so far it's almost identical to `assert.throws(fn, object)` in case it was used with a function as first argument. It had a magical property check that allowed to verify a functions `type` in case `type` was passed used in the validation object. This pattern is now completely removed and `assert.throws()` should be used instead. The main intent for `common.expectsError()` is to verify error cases for callback based APIs. This is now more flexible by accepting all validation possibilites that `assert.throws()` accepts as well. No magical properties exist anymore. This reduces surprising behavior for developers who are not used to the Node.js core code base. This has the side effect that `common` is used significantly less frequent. PR-URL: https://github.com/nodejs/node/pull/31092 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
395 files changed
+2120
-2170
No files matched your search
@@ -173,29 +173,29 @@ assert.strictEqual(decoder.write(Buffer.from('f4', 'hex')), '');
|
||||
assert.strictEqual(decoder.write(Buffer.from('bde5', 'hex')), '\ufffd\ufffd');
|
||||
assert.strictEqual(decoder.end(), '\ufffd');
|
||||
|
||||
common.expectsError(
|
||||
assert.throws(
|
||||
() => new StringDecoder(1),
|
||||
{
|
||||
code: 'ERR_UNKNOWN_ENCODING',
|
||||
type: TypeError,
|
||||
name: 'TypeError',
|
||||
message: 'Unknown encoding: 1'
|
||||
}
|
||||
);
|
||||
|
||||
common.expectsError(
|
||||
assert.throws(
|
||||
() => new StringDecoder('test'),
|
||||
{
|
||||
code: 'ERR_UNKNOWN_ENCODING',
|
||||
type: TypeError,
|
||||
name: 'TypeError',
|
||||
message: 'Unknown encoding: test'
|
||||
}
|
||||
);
|
||||
|
||||
common.expectsError(
|
||||
assert.throws(
|
||||
() => new StringDecoder('utf8').write(null),
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
type: TypeError,
|
||||
name: 'TypeError',
|
||||
message: 'The "buf" argument must be an instance of Buffer, TypedArray,' +
|
||||
' or DataView. Received null'
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user