Skip to content

Commit 27cd99b

Browse files
juanarboldanielleadams
authored andcommitted
test: improve test coverage for eventtarget
PR-URL: #33733 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 541be52 commit 27cd99b

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

test/parallel/test-eventtarget.js

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ let asyncTest = Promise.resolve();
5656
ev.preventDefault();
5757
strictEqual(ev.defaultPrevented, false);
5858
}
59+
{
60+
[
61+
'foo',
62+
1,
63+
false,
64+
function() {},
65+
].forEach((i) => (
66+
throws(() => new Event('foo', i), {
67+
code: 'ERR_INVALID_ARG_TYPE',
68+
name: 'TypeError',
69+
message: 'The "options" argument must be of type object.' +
70+
common.invalidArgTypeHelper(i)
71+
})
72+
));
73+
}
5974
{
6075
const ev = new Event('foo');
6176
strictEqual(ev.cancelBubble, false);
@@ -221,31 +236,33 @@ let asyncTest = Promise.resolve();
221236
false
222237
].forEach((i) => {
223238
throws(() => target.dispatchEvent(i), {
224-
code: 'ERR_INVALID_ARG_TYPE'
239+
code: 'ERR_INVALID_ARG_TYPE',
240+
name: 'TypeError',
241+
message: 'The "event" argument must be an instance of Event.' +
242+
common.invalidArgTypeHelper(i)
225243
});
226244
});
227245

246+
const err = (arg) => ({
247+
code: 'ERR_INVALID_ARG_TYPE',
248+
name: 'TypeError',
249+
message: 'The "listener" argument must be an instance of EventListener.' +
250+
common.invalidArgTypeHelper(arg)
251+
});
252+
228253
[
229254
'foo',
230255
1,
231256
{}, // No handleEvent function
232-
false,
233-
].forEach((i) => {
234-
throws(() => target.addEventListener('foo', i), {
235-
code: 'ERR_INVALID_ARG_TYPE'
236-
});
237-
});
257+
false
258+
].forEach((i) => throws(() => target.addEventListener('foo', i), err(i)));
238259

239260
[
240261
'foo',
241262
1,
242263
{}, // No handleEvent function
243264
false
244-
].forEach((i) => {
245-
throws(() => target.removeEventListener('foo', i), {
246-
code: 'ERR_INVALID_ARG_TYPE'
247-
});
248-
});
265+
].forEach((i) => throws(() => target.addEventListener('foo', i), err(i)));
249266
}
250267

251268
{

0 commit comments

Comments
 (0)