0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-event-emitter-once.js
Gibson Fahnestock 7a0e462f9f test: use eslint to fix var->const/let
Manually fix issues that eslint --fix couldn't do automatically.

PR-URL: https://github.com/nodejs/node/pull/10685
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
2017-01-11 11:43:52 +00:00

37 lines
782 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const EventEmitter = require('events');
const e = new EventEmitter();
e.once('hello', common.mustCall(function(a, b) {}));
e.emit('hello', 'a', 'b');
e.emit('hello', 'a', 'b');
e.emit('hello', 'a', 'b');
e.emit('hello', 'a', 'b');
const remove = function() {
common.fail('once->foo should not be emitted');
};
e.once('foo', remove);
e.removeListener('foo', remove);
e.emit('foo');
e.once('e', common.mustCall(function() {
e.emit('e');
}));
e.once('e', common.mustCall(function() {}));
e.emit('e');
// Verify that the listener must be a function
assert.throws(() => {
const ee = new EventEmitter();
ee.once('foo', null);
}, /^TypeError: "listener" argument must be a function$/);