mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
d8a0364ad5
Update docs and type checking for AsyncResource type PR-URL: https://github.com/nodejs/node/pull/15103 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
42 lines
886 B
JavaScript
42 lines
886 B
JavaScript
'use strict';
|
|
|
|
// This tests that AsyncResource throws an error if bad parameters are passed
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const async_hooks = require('async_hooks');
|
|
const { AsyncResource } = async_hooks;
|
|
|
|
// Setup init hook such parameters are validated
|
|
async_hooks.createHook({
|
|
init() {}
|
|
}).enable();
|
|
|
|
assert.throws(() => {
|
|
return new AsyncResource();
|
|
}, common.expectsError({
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
type: TypeError,
|
|
}));
|
|
|
|
assert.throws(() => {
|
|
new AsyncResource('');
|
|
}, common.expectsError({
|
|
code: 'ERR_ASYNC_TYPE',
|
|
type: TypeError,
|
|
}));
|
|
|
|
assert.throws(() => {
|
|
new AsyncResource('type', -4);
|
|
}, common.expectsError({
|
|
code: 'ERR_INVALID_ASYNC_ID',
|
|
type: RangeError,
|
|
}));
|
|
|
|
assert.throws(() => {
|
|
new AsyncResource('type', Math.PI);
|
|
}, common.expectsError({
|
|
code: 'ERR_INVALID_ASYNC_ID',
|
|
type: RangeError,
|
|
}));
|