1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const EventEmitter = require('events'); 5 6const EE = new EventEmitter(); 7const theErr = new Error('MyError'); 8 9EE.on( 10 EventEmitter.errorMonitor, 11 common.mustCall(function onErrorMonitor(e) { 12 assert.strictEqual(e, theErr); 13 }, 3) 14); 15 16// Verify with no error listener 17assert.throws( 18 () => EE.emit('error', theErr), theErr 19); 20 21// Verify with error listener 22EE.once('error', common.mustCall((e) => assert.strictEqual(e, theErr))); 23EE.emit('error', theErr); 24 25 26// Verify it works with once 27process.nextTick(() => EE.emit('error', theErr)); 28assert.rejects(EventEmitter.once(EE, 'notTriggered'), theErr); 29 30// Only error events trigger error monitor 31EE.on('aEvent', common.mustCall()); 32EE.emit('aEvent'); 33