Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor events tests for invalid listeners #32769

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions test/parallel/test-event-emitter-add-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,3 @@ const EventEmitter = require('events');
// listeners were added.
assert.deepStrictEqual(ee.listeners('hello'), [listen2, listen1]);
}

// Verify that the listener must be a function
assert.throws(() => {
const ee = new EventEmitter();
ee.on('foo', null);
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "listener" argument must be of type function. ' +
'Received null'
});
20 changes: 20 additions & 0 deletions test/parallel/test-event-emitter-invalid-listener.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'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`);
}
11 changes: 0 additions & 11 deletions test/parallel/test-event-emitter-once.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,6 @@ e.once('e', common.mustCall());

e.emit('e');

// Verify that the listener must be a function
assert.throws(() => {
const ee = new EventEmitter();
ee.once('foo', null);
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "listener" argument must be of type function. ' +
'Received null'
});

{
// once() has different code paths based on the number of arguments being
// emitted. Verify that all of the cases are covered.
Expand Down
11 changes: 0 additions & 11 deletions test/parallel/test-event-emitter-prepend.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@ myEE.prependOnceListener('foo',

myEE.emit('foo');

// Verify that the listener must be a function
assert.throws(() => {
const ee = new EventEmitter();
ee.prependOnceListener('foo', null);
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "listener" argument must be of type function. ' +
'Received null'
});

// Test fallback if prependListener is undefined.
const stream = require('stream');

Expand Down
11 changes: 0 additions & 11 deletions test/parallel/test-event-emitter-remove-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,6 @@ function listener2() {}
assert.deepStrictEqual(ee, ee.removeListener('foo', () => {}));
}

// Verify that the removed listener must be a function
assert.throws(() => {
const ee = new EventEmitter();
ee.removeListener('foo', null);
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "listener" argument must be of type function. ' +
'Received null'
});

{
const ee = new EventEmitter();
const listener = () => {};
Expand Down