From 27cd99b217ab091a1e8ca2e5872bf1173ff2d06a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Arboleda?= Date: Thu, 4 Jun 2020 21:49:06 -0500 Subject: [PATCH] test: improve test coverage for eventtarget PR-URL: https://github.com/nodejs/node/pull/33733 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig --- test/parallel/test-eventtarget.js | 41 ++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/test/parallel/test-eventtarget.js b/test/parallel/test-eventtarget.js index 1e505cc7c48e5a..9487c22e26d1af 100644 --- a/test/parallel/test-eventtarget.js +++ b/test/parallel/test-eventtarget.js @@ -56,6 +56,21 @@ let asyncTest = Promise.resolve(); ev.preventDefault(); strictEqual(ev.defaultPrevented, false); } +{ + [ + 'foo', + 1, + false, + function() {}, + ].forEach((i) => ( + throws(() => new Event('foo', i), { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError', + message: 'The "options" argument must be of type object.' + + common.invalidArgTypeHelper(i) + }) + )); +} { const ev = new Event('foo'); strictEqual(ev.cancelBubble, false); @@ -221,31 +236,33 @@ let asyncTest = Promise.resolve(); false ].forEach((i) => { throws(() => target.dispatchEvent(i), { - code: 'ERR_INVALID_ARG_TYPE' + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError', + message: 'The "event" argument must be an instance of Event.' + + common.invalidArgTypeHelper(i) }); }); + const err = (arg) => ({ + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError', + message: 'The "listener" argument must be an instance of EventListener.' + + common.invalidArgTypeHelper(arg) + }); + [ 'foo', 1, {}, // No handleEvent function - false, - ].forEach((i) => { - throws(() => target.addEventListener('foo', i), { - code: 'ERR_INVALID_ARG_TYPE' - }); - }); + false + ].forEach((i) => throws(() => target.addEventListener('foo', i), err(i))); [ 'foo', 1, {}, // No handleEvent function false - ].forEach((i) => { - throws(() => target.removeEventListener('foo', i), { - code: 'ERR_INVALID_ARG_TYPE' - }); - }); + ].forEach((i) => throws(() => target.addEventListener('foo', i), err(i))); } {