Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: improve coverage of lib/events.js #38582

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions test/parallel/test-event-emitter-emit-context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const EventEmitter = require('events');

// Test emit called by other context
const EE = new EventEmitter();

// Works as expected if the context has no `constructor.name`
{
const ctx = Object.create(null);
assert.throws(
() => EE.emit.call(ctx, 'error', new Error('foo')),
common.expectsError({ name: 'Error', message: 'foo' })
);
}

assert.strictEqual(EE.emit.call({}, 'foo'), false);
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ async function basic() {
assert.strictEqual(ee.listenerCount('error'), 0);
}

async function invalidArgType() {
assert.throws(() => on({}, 'foo'), common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
}));
}

async function error() {
const ee = new EventEmitter();
const _err = new Error('kaboom');
Expand Down Expand Up @@ -359,6 +366,7 @@ async function abortableOnAfterDone() {
async function run() {
const funcs = [
basic,
invalidArgType,
error,
errorDelayed,
throwInLoop,
Expand Down