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: exercise EE function type checking paths #8168

Merged
merged 1 commit into from
Sep 9, 2016

Conversation

cjihrig
Copy link
Contributor

@cjihrig cjihrig commented Aug 18, 2016

Checklist
  • make -j4 test (UNIX), or vcbuild test nosign (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

test

Description of change

This commit adds tests for on(), once(), removeListener(), and prependOnceListener(), which all throw a TypeError if the listener argument is not a function.

@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Aug 18, 2016
@cjihrig cjihrig added the events Issues and PRs related to the events subsystem / EventEmitter. label Aug 18, 2016
@@ -42,7 +42,7 @@ e.emit('hello', 'a', 'b');


// just make sure that this doesn't throw:
var f = new events.EventEmitter();
var f = new EventEmitter();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer wrapping in a block rather than having a new variable name?

or is that too large of a change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to const and did some refactoring of this file for scoping, dropping the on exit handler, preferring strictEqual(), etc.

@Trott
Copy link
Member

Trott commented Aug 18, 2016

LGTM if CI is green

@Fishrock123
Copy link
Contributor

const ee = new EventEmitter();

ee.on('foo', null);
}, /^TypeError: "listener" argument must be a function$/);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a final message param may be helpful (I forget but I don't think throws logs the regex?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would you like the message to be? If an incorrect error is thrown, the message isn't used at all. If an error isn't thrown, it says AssertionError: Missing expected exception., which is what I would have used as the message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping @Fishrock123 on ideas here.

@Fishrock123
Copy link
Contributor

lgtm with ci & nits

// Verify that the listener must be a function
assert.throws(() => {
const ee = new EventEmitter();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extremely minor nit: unnecessary blank line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dunno. A blank line after a variable declaration is pretty common throughout the codebase.

@jasnell
Copy link
Member

jasnell commented Aug 19, 2016

LGTM with the nits addressed.

@cjihrig cjihrig force-pushed the ee-test branch 2 times, most recently from 31ba26c to e80e56f Compare August 19, 2016 16:13
@cjihrig
Copy link
Contributor Author

cjihrig commented Sep 1, 2016

This commit adds tests for on(), once(), removeListener(),
and prependOnceListener(), which all throw a TypeError if
the listener argument is not a function.

PR-URL: nodejs#8168
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@cjihrig cjihrig merged commit e57ff45 into nodejs:master Sep 9, 2016
@cjihrig cjihrig deleted the ee-test branch September 9, 2016 23:54
Fishrock123 pushed a commit that referenced this pull request Sep 14, 2016
This commit adds tests for on(), once(), removeListener(),
and prependOnceListener(), which all throw a TypeError if
the listener argument is not a function.

PR-URL: #8168
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@MylesBorins
Copy link
Contributor

This does not land cleanly in LTS. Added dont-land label. Please feel free to manually backport

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
events Issues and PRs related to the events subsystem / EventEmitter. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants