-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: refactor events tests for invalid listeners
- Loading branch information
Showing
5 changed files
with
20 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters