2023-02-20 10:35:04 -05:00
|
|
|
// deno-fmt-ignore-file
|
|
|
|
// deno-lint-ignore-file
|
|
|
|
|
|
|
|
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
|
|
|
// Taken from Node 18.12.1
|
2024-04-02 18:24:55 -04:00
|
|
|
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
|
2023-02-20 10:35:04 -05: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
|
|
|
|
assert.throws(
|
|
|
|
() => 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));
|
2024-06-11 07:41:44 -04:00
|
|
|
assert.rejects(EventEmitter.once(EE, 'notTriggered'), theErr).then(common.mustCall());
|
2023-02-20 10:35:04 -05:00
|
|
|
|
|
|
|
// Only error events trigger error monitor
|
|
|
|
EE.on('aEvent', common.mustCall());
|
|
|
|
EE.emit('aEvent');
|