11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst EventEmitter = require('events');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst EE = new EventEmitter();
71cb0ef41Sopenharmony_ciconst theErr = new Error('MyError');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciEE.on(
101cb0ef41Sopenharmony_ci  EventEmitter.errorMonitor,
111cb0ef41Sopenharmony_ci  common.mustCall(function onErrorMonitor(e) {
121cb0ef41Sopenharmony_ci    assert.strictEqual(e, theErr);
131cb0ef41Sopenharmony_ci  }, 3)
141cb0ef41Sopenharmony_ci);
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci// Verify with no error listener
171cb0ef41Sopenharmony_ciassert.throws(
181cb0ef41Sopenharmony_ci  () => EE.emit('error', theErr), theErr
191cb0ef41Sopenharmony_ci);
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci// Verify with error listener
221cb0ef41Sopenharmony_ciEE.once('error', common.mustCall((e) => assert.strictEqual(e, theErr)));
231cb0ef41Sopenharmony_ciEE.emit('error', theErr);
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci// Verify it works with once
271cb0ef41Sopenharmony_ciprocess.nextTick(() => EE.emit('error', theErr));
281cb0ef41Sopenharmony_ciassert.rejects(EventEmitter.once(EE, 'notTriggered'), theErr);
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci// Only error events trigger error monitor
311cb0ef41Sopenharmony_ciEE.on('aEvent', common.mustCall());
321cb0ef41Sopenharmony_ciEE.emit('aEvent');
33