Skip to content

Commit 81bbeab

Browse files
pd4d10targos
authored andcommitted
test: improve coverage of lib/events.js
PR-URL: #38582 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
1 parent 405b50c commit 81bbeab

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
@@ -35,6 +35,13 @@ async function basic() {
3535
assert.strictEqual(ee.listenerCount('error'), 0);
3636
}
3737

38+
async function invalidArgType() {
39+
assert.throws(() => on({}, 'foo'), common.expectsError({
40+
code: 'ERR_INVALID_ARG_TYPE',
41+
name: 'TypeError',
42+
}));
43+
}
44+
3845
async function error() {
3946
const ee = new EventEmitter();
4047
const _err = new Error('kaboom');
@@ -359,6 +366,7 @@ async function abortableOnAfterDone() {
359366
async function run() {
360367
const funcs = [
361368
basic,
369+
invalidArgType,
362370
error,
363371
errorDelayed,
364372
throwInLoop,

0 commit comments

Comments
 (0)