2019-12-12 20:08:42 +00:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const EventEmitter = require('events');
|
|
|
|
|
|
|
|
const EE = new EventEmitter();
|
|
|
|
const theErr = new Error('MyError');
|
|
|
|
|
|
|
|
EE.on(
|
|
|
|
EventEmitter.errorMonitor,
|
|
|
|
common.mustCall(function onErrorMonitor(e) {
|
|
|
|
assert.strictEqual(e, theErr);
|
|
|
|
}, 3)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Verify with no error listener
|
2019-12-25 17:02:16 +00:00
|
|
|
assert.throws(
|
2019-12-12 20:08:42 +00:00
|
|
|
() => EE.emit('error', theErr), theErr
|
|
|
|
);
|
|
|
|
|
|
|
|
// Verify with error listener
|
|
|
|
EE.once('error', common.mustCall((e) => assert.strictEqual(e, theErr)));
|
|
|
|
EE.emit('error', theErr);
|
|
|
|
|
|
|
|
|
|
|
|
// Verify it works with once
|
|
|
|
process.nextTick(() => EE.emit('error', theErr));
|
2023-10-23 17:55:50 +00:00
|
|
|
assert.rejects(EventEmitter.once(EE, 'notTriggered'), theErr).then(common.mustCall());
|
2019-12-12 20:08:42 +00:00
|
|
|
|
|
|
|
// Only error events trigger error monitor
|
|
|
|
EE.on('aEvent', common.mustCall());
|
|
|
|
EE.emit('aEvent');
|