node/test/parallel/test-event-emitter-emit-context.js
Rongjian Zhang a596fdf4d6 test: improve coverage of lib/events.js
PR-URL: https://github.com/nodejs/node/pull/38582
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
2021-06-11 02:35:14 +00:00

19 lines
486 B
JavaScript

'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);