1'use strict'; 2 3// This tests that AsyncResource throws an error if bad parameters are passed 4 5require('../common'); 6const assert = require('assert'); 7const async_hooks = require('async_hooks'); 8const { AsyncResource } = async_hooks; 9 10// Setup init hook such parameters are validated 11async_hooks.createHook({ 12 init() {} 13}).enable(); 14 15assert.throws(() => { 16 return new AsyncResource(); 17}, { 18 code: 'ERR_INVALID_ARG_TYPE', 19 name: 'TypeError', 20}); 21 22assert.throws(() => { 23 new AsyncResource(''); 24}, { 25 code: 'ERR_ASYNC_TYPE', 26 name: 'TypeError', 27}); 28 29assert.throws(() => { 30 new AsyncResource('type', -4); 31}, { 32 code: 'ERR_INVALID_ASYNC_ID', 33 name: 'RangeError', 34}); 35 36assert.throws(() => { 37 new AsyncResource('type', Math.PI); 38}, { 39 code: 'ERR_INVALID_ASYNC_ID', 40 name: 'RangeError', 41}); 42