From f686f7346506ef8970d95b9f226f2c5bef95a8e2 Mon Sep 17 00:00:00 2001 From: Gergely Nemeth Date: Wed, 31 May 2017 10:01:26 +0200 Subject: [PATCH] test: add coverage for AsyncResource constructor PR-URL: https://github.com/nodejs/node/pull/13327 Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Refael Ackermann Reviewed-By: Trevor Norris --- ...st-async-wrap-asyncresource-constructor.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 test/parallel/test-async-wrap-asyncresource-constructor.js 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..c8ecf047405510 --- /dev/null +++ b/test/parallel/test-async-wrap-asyncresource-constructor.js @@ -0,0 +1,23 @@ +'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; + +assert.throws(() => { + return new AsyncResource(); +}, /^TypeError: type must be a string with length > 0$/); + +assert.throws(() => { + new AsyncResource(''); +}, /^TypeError: type must be a string with length > 0$/); + +assert.throws(() => { + new AsyncResource('type', -4); +}, /^RangeError: triggerId must be an unsigned integer$/); + +assert.throws(() => { + new AsyncResource('type', Math.PI); +}, /^RangeError: triggerId must be an unsigned integer$/);