test: improve test coverage for eventtarget

PR-URL: https://github.com/nodejs/node/pull/33733
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Juan José Arboleda 2020-06-04 21:49:06 -05:00
parent e817c365ab
commit fb2f3cc828

View File

@ -56,6 +56,21 @@ let asyncTest = Promise.resolve();
ev.preventDefault(); ev.preventDefault();
strictEqual(ev.defaultPrevented, false); 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'); const ev = new Event('foo');
strictEqual(ev.cancelBubble, false); strictEqual(ev.cancelBubble, false);
@ -221,19 +236,18 @@ let asyncTest = Promise.resolve();
false false
].forEach((i) => { ].forEach((i) => {
throws(() => target.dispatchEvent(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) => ({
'foo', code: 'ERR_INVALID_ARG_TYPE',
1, name: 'TypeError',
{}, // No handleEvent function message: 'The "listener" argument must be an instance of EventListener.' +
false, common.invalidArgTypeHelper(arg)
].forEach((i) => {
throws(() => target.addEventListener('foo', i), {
code: 'ERR_INVALID_ARG_TYPE'
});
}); });
[ [
@ -241,11 +255,14 @@ let asyncTest = Promise.resolve();
1, 1,
{}, // No handleEvent function {}, // No handleEvent function
false false
].forEach((i) => { ].forEach((i) => throws(() => target.addEventListener('foo', i), err(i)));
throws(() => target.removeEventListener('foo', i), {
code: 'ERR_INVALID_ARG_TYPE' [
}); 'foo',
}); 1,
{}, // No handleEvent function
false
].forEach((i) => throws(() => target.addEventListener('foo', i), err(i)));
} }
{ {