()
| 10 | } = require('internal/event_target'); |
| 11 | |
| 12 | async function basic() { |
| 13 | const ee = new EventEmitter(); |
| 14 | process.nextTick(() => { |
| 15 | ee.emit('foo', 'bar'); |
| 16 | // 'bar' is a spurious event, we are testing |
| 17 | // that it does not show up in the iterable |
| 18 | ee.emit('bar', 24); |
| 19 | ee.emit('foo', 42); |
| 20 | }); |
| 21 | |
| 22 | const iterable = on(ee, 'foo'); |
| 23 | |
| 24 | const expected = [['bar'], [42]]; |
| 25 | |
| 26 | for await (const event of iterable) { |
| 27 | const current = expected.shift(); |
| 28 | |
| 29 | assert.deepStrictEqual(current, event); |
| 30 | |
| 31 | if (expected.length === 0) { |
| 32 | break; |
| 33 | } |
| 34 | } |
| 35 | assert.strictEqual(ee.listenerCount('foo'), 0); |
| 36 | assert.strictEqual(ee.listenerCount('error'), 0); |
| 37 | } |
| 38 | |
| 39 | async function invalidArgType() { |
| 40 | assert.throws(() => on({}, 'foo'), common.expectsError({ |
nothing calls this directly
no test coverage detected
searching dependent graphs…