| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,18 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const EventEmitter = require('events'); | ||
| 5 | + | ||
| 6 | + // Test emit called by other context | ||
| 7 | + const EE = new EventEmitter(); | ||
| 8 | + | ||
| 9 | + // Works as expected if the context has no `constructor.name` | ||
| 10 | + { | ||
| 11 | + const ctx = Object.create(null); | ||
| 12 | + assert.throws( | ||
| 13 | + () => EE.emit.call(ctx, 'error', new Error('foo')), | ||
| 14 | + common.expectsError({ name: 'Error', message: 'foo' }) | ||
| 15 | + ); | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + assert.strictEqual(EE.emit.call({}, 'foo'), false); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,6 +35,13 @@ async function basic() { | |||
| 35 | 35 | assert.strictEqual(ee.listenerCount('error'), 0); | |
| 36 | 36 | } | |
| 37 | 37 | ||
| 38 | + async function invalidArgType() { | ||
| 39 | + assert.throws(() => on({}, 'foo'), common.expectsError({ | ||
| 40 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 41 | + name: 'TypeError', | ||
| 42 | + })); | ||
| 43 | + } | ||
| 44 | + | ||
| 38 | 45 | async function error() { | |
| 39 | 46 | const ee = new EventEmitter(); | |
| 40 | 47 | const _err = new Error('kaboom'); | |
@@ -359,6 +366,7 @@ async function abortableOnAfterDone() { | |||
| 359 | 366 | async function run() { | |
| 360 | 367 | const funcs = [ | |
| 361 | 368 | basic, | |
| 369 | + invalidArgType, | ||
| 362 | 370 | error, | |
| 363 | 371 | errorDelayed, | |
| 364 | 372 | throwInLoop, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments