Skip to content

Commit b3b5995

Browse files
pd4d10richardlau
authored andcommitted
test: improve coverage of lib/events.js
PR-URL: #38582 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Zijian Liu <[email protected]>
1 parent cd48ee7 commit b3b5995

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const EventEmitter = require('events');
5+
6+
// Test emit called by other context
7+
const EE = new EventEmitter();
8+
9+
// Works as expected if the context has no `constructor.name`
10+
{
11+
const ctx = Object.create(null);
12+
assert.throws(
13+
() => EE.emit.call(ctx, 'error', new Error('foo')),
14+
common.expectsError({ name: 'Error', message: 'foo' })
15+
);
16+
}
17+
18+
assert.strictEqual(EE.emit.call({}, 'foo'), false);

test/parallel/test-event-on-async-iterator.js renamed to test/parallel/test-events-on-async-iterator.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ async function basic() {
3737
assert.strictEqual(ee.listenerCount('error'), 0);
3838
}
3939

40+
async function invalidArgType() {
41+
assert.throws(() => on({}, 'foo'), common.expectsError({
42+
code: 'ERR_INVALID_ARG_TYPE',
43+
name: 'TypeError',
44+
}));
45+
}
46+
4047
async function error() {
4148
const ee = new EventEmitter();
4249
const _err = new Error('kaboom');
@@ -363,6 +370,7 @@ async function abortableOnAfterDone() {
363370
async function run() {
364371
const funcs = [
365372
basic,
373+
invalidArgType,
366374
error,
367375
errorDelayed,
368376
throwInLoop,

0 commit comments

Comments
 (0)