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 numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
'use strict';
constcommon=require('../common');
constassert=require('assert');
constEventEmitter=require('events');

// Test emit called by other context
constEE=newEventEmitter();

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

assert.strictEqual(EE.emit.call({},'foo'),false);
Original file line numberDiff line numberDiff 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 DownExpand Up@@ -359,6 +366,7 @@ async function abortableOnAfterDone(){
async function run(){
const funcs = [
basic,
invalidArgType,
error,
errorDelayed,
throwInLoop,
Expand Down