Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRongjian Zhang <pd4d10@gmail.com>2021-05-07 16:49:07 +0300
committerNode.js GitHub Bot <github-bot@iojs.org>2021-06-11 05:35:14 +0300
commita596fdf4d6152c0bdf43417fd63684ccfcfcd098 (patch)
tree5c9903c2d2a7de92ec0be382510b9d862f11d6c6 /test
parentbf2473d384ea4b9a0c5e09e046a263c6a31009d7 (diff)
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')
-rw-r--r--test/parallel/test-event-emitter-emit-context.js18
-rw-r--r--test/parallel/test-events-on-async-iterator.js (renamed from test/parallel/test-event-on-async-iterator.js)8
2 files changed, 26 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 00000000000..82e4b595185
--- /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);
diff --git a/test/parallel/test-event-on-async-iterator.js b/test/parallel/test-events-on-async-iterator.js
index 192326e12bc..dbd27a8a446 100644
--- a/test/parallel/test-event-on-async-iterator.js
+++ b/test/parallel/test-events-on-async-iterator.js
@@ -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');
@@ -359,6 +366,7 @@ async function abortableOnAfterDone() {
async function run() {
const funcs = [
basic,
+ invalidArgType,
error,
errorDelayed,
throwInLoop,