node/test/parallel/test-event-emitter-invalid-listener.js
Rich Trott d5d7a416c7
test: add trailing commas in event tests
As much as I would like to do this everywhere and then modify the lint
rule to enforce it, the churn would be too big. However if we're going
to have relatively frequent nits for this sort of thing (as we do), I'd
prefer we migrate a few files at a time to never actually getting around
to doing it.

Ref: https://github.com/nodejs/node/pull/45448#pullrequestreview-1179370442
PR-URL: https://github.com/nodejs/node/pull/45466
Reviewed-By: James M Snell <jasnell@gmail.com>
2022-11-22 23:03:33 +00:00

21 lines
616 B
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const EventEmitter = require('events');
const eventsMethods = ['on', 'once', 'removeListener', 'prependOnceListener'];
// Verify that the listener must be a function for events methods
for (const method of eventsMethods) {
assert.throws(() => {
const ee = new EventEmitter();
ee[method]('foo', null);
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "listener" argument must be of type function. ' +
'Received null',
}, `event.${method}('foo', null) should throw the proper error`);
}