summaryrefslogtreecommitdiff
path: root/test/parallel/test-event-emitter-emit-context.js
diff options
context:
space:
mode:
authorRongjian Zhang <pd4d10@gmail.com>2021-05-07 21:49:07 +0800
committerNode.js GitHub Bot <github-bot@iojs.org>2021-06-11 02:35:14 +0000
commita596fdf4d6152c0bdf43417fd63684ccfcfcd098 (patch)
tree5c9903c2d2a7de92ec0be382510b9d862f11d6c6 /test/parallel/test-event-emitter-emit-context.js
parentbf2473d384ea4b9a0c5e09e046a263c6a31009d7 (diff)
downloadnode-new-a596fdf4d6152c0bdf43417fd63684ccfcfcd098.tar.gz
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>
Diffstat (limited to 'test/parallel/test-event-emitter-emit-context.js')
-rw-r--r--test/parallel/test-event-emitter-emit-context.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/parallel/test-event-emitter-emit-context.js b/test/parallel/test-event-emitter-emit-context.js
new file mode 100644
index 0000000000..82e4b59518
--- /dev/null
+++ b/test/parallel/test-event-emitter-emit-context.js
@@ -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);