Skip to content
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