| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b764269 commit 5bc130b
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,3 +56,17 @@ for (const obj of throwsObjs) { | |||
| 56 | 56 | } | |
| 57 | 57 | ||
| 58 | 58 | e.emit('maxListeners'); | |
| 59 | + | ||
| 60 | + { | ||
| 61 | + const { EventEmitter, defaultMaxListeners } = events; | ||
| 62 | + for (const obj of throwsObjs) { | ||
| 63 | + assert.throws(() => EventEmitter.setMaxListeners(obj), { | ||
| 64 | + code: 'ERR_OUT_OF_RANGE', | ||
| 65 | + }); | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + assert.throws( | ||
| 69 | + () => EventEmitter.setMaxListeners(defaultMaxListeners, 'INVALID_EMITTER'), | ||
| 70 | + { code: 'ERR_INVALID_ARG_TYPE' } | ||
| 71 | + ); | ||
| 72 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,18 @@ async function onceAnEvent() { | |||
| 23 | 23 | strictEqual(ee.listenerCount('myevent'), 0); | |
| 24 | 24 | } | |
| 25 | 25 | ||
| 26 | + async function onceAnEventWithNullOptions() { | ||
| 27 | + const ee = new EventEmitter(); | ||
| 28 | + | ||
| 29 | + process.nextTick(() => { | ||
| 30 | + ee.emit('myevent', 42); | ||
| 31 | + }); | ||
| 32 | + | ||
| 33 | + const [value] = await once(ee, 'myevent', null); | ||
| 34 | + strictEqual(value, 42); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + | ||
| 26 | 38 | async function onceAnEventWithTwoArgs() { | |
| 27 | 39 | const ee = new EventEmitter(); | |
| 28 | 40 | ||
@@ -195,6 +207,7 @@ async function eventTargetAbortSignalAfterEvent() { | |||
| 195 | 207 | ||
| 196 | 208 | Promise.all([ | |
| 197 | 209 | onceAnEvent(), | |
| 210 | + onceAnEventWithNullOptions(), | ||
| 198 | 211 | onceAnEventWithTwoArgs(), | |
| 199 | 212 | catchesErrors(), | |
| 200 | 213 | stopListeningAfterCatchingError(), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ const common = require('../common'); | |||
| 4 | 4 | ||
| 5 | 5 | const { | |
| 6 | 6 | deepStrictEqual, | |
| 7 | + throws | ||
| 7 | 8 | } = require('assert'); | |
| 8 | 9 | ||
| 9 | 10 | const { getEventListeners, EventEmitter } = require('events'); | |
@@ -34,3 +35,9 @@ const { getEventListeners, EventEmitter } = require('events'); | |||
| 34 | 35 | deepStrictEqual(getEventListeners(target, 'bar'), []); | |
| 35 | 36 | deepStrictEqual(getEventListeners(target, 'baz'), [fn1]); | |
| 36 | 37 | } | |
| 38 | + | ||
| 39 | + { | ||
| 40 | + throws(() => { | ||
| 41 | + getEventListeners('INVALID_EMITTER'); | ||
| 42 | + }, /ERR_INVALID_ARG_TYPE/); | ||
| 43 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,7 @@ const { | |||
| 13 | 13 | ||
| 14 | 14 | const { once } = require('events'); | |
| 15 | 15 | ||
| 16 | - const { promisify } = require('util'); | ||
| 16 | + const { promisify, inspect } = require('util'); | ||
| 17 | 17 | const delay = promisify(setTimeout); | |
| 18 | 18 | ||
| 19 | 19 | // The globals are defined. | |
@@ -541,3 +541,32 @@ let asyncTest = Promise.resolve(); | |||
| 541 | 541 | et.addEventListener('foo', listener); | |
| 542 | 542 | et.dispatchEvent(new Event('foo')); | |
| 543 | 543 | } | |
| 544 | + | ||
| 545 | + { | ||
| 546 | + const ev = new Event('test'); | ||
| 547 | + const evConstructorName = inspect(ev, { | ||
| 548 | + depth: -1 | ||
| 549 | + }); | ||
| 550 | + strictEqual(evConstructorName, 'Event'); | ||
| 551 | + | ||
| 552 | + const inspectResult = inspect(ev, { | ||
| 553 | + depth: 1 | ||
| 554 | + }); | ||
| 555 | + ok(inspectResult.includes('Event')); | ||
| 556 | + } | ||
| 557 | + | ||
| 558 | + { | ||
| 559 | + const et = new EventTarget(); | ||
| 560 | + const inspectResult = inspect(et, { | ||
| 561 | + depth: 1 | ||
| 562 | + }); | ||
| 563 | + ok(inspectResult.includes('EventTarget')); | ||
| 564 | + } | ||
| 565 | + | ||
| 566 | + { | ||
| 567 | + const ev = new Event('test'); | ||
| 568 | + strictEqual(ev.constructor.name, 'Event'); | ||
| 569 | + | ||
| 570 | + const et = new EventTarget(); | ||
| 571 | + strictEqual(et.constructor.name, 'EventTarget'); | ||
| 572 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments