diff --git a/test/parallel/test-async-wrap-asyncresource-constructor.js b/test/parallel/test-async-wrap-asyncresource-constructor.js new file mode 100644 index 00000000000000..a68a7837c957dd --- /dev/null +++ b/test/parallel/test-async-wrap-asyncresource-constructor.js @@ -0,0 +1,24 @@ +'use strict'; +require('../common'); + +// This tests that AsyncResource throws an error if bad parameters are passed + +const assert = require('assert'); +const AsyncResource = require('async_hooks').AsyncResource; +const async_wrap = process.binding('async_wrap'); + +assert.throws(() => { + return new AsyncResource(); +}, new RegExp('^TypeError: type must be a string with length > 0$')); + +assert.throws(() => { + new AsyncResource(''); +}, new RegExp('^TypeError: type must be a string with length > 0$')); + +assert.throws(() => { + new AsyncResource('type', -4); +}, new RegExp('^RangeError: triggerId must be an unsigned integer$')); + +assert.throws(() => { + new AsyncResource('type', Math.PI); +}, new RegExp('^RangeError: triggerId must be an unsigned integer$'));