Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 81bbeab

Browse filesBrowse 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
Copy full SHA for 81bbeab

File tree

Expand file treeCollapse file tree

2 files changed

+26
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+26
-0
lines changed
Open diff view settings
Collapse file
+18Lines 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);
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-events-on-async-iterator.js
+8Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.