Skip to content

Commit

Permalink
test: improve test coverage for eventtarget
Browse files Browse the repository at this point in the history
PR-URL: #33733
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
juanarbol authored and danielleadams committed Oct 6, 2020
1 parent 541be52 commit 27cd99b
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions test/parallel/test-eventtarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)));
}

{
Expand Down

0 comments on commit 27cd99b

Please sign in to comment.