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

doc: improve common.mustCall() explanation #10390

Closed
wants to merge 1 commit into from

Conversation

Trott
Copy link
Member

@Trott Trott commented Dec 21, 2016

Checklist
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

test

Description of change

@Trott Trott added the test Issues and PRs related to the tests. label Dec 21, 2016
@Trott Trott mentioned this pull request Dec 21, 2016
1 task
@mscdex mscdex added the doc Issues and PRs related to the documentations. label Dec 21, 2016
@sam-github
Copy link
Contributor

Maybe not the right time to bring this up, but the message printed when it fails doesn't include the text "common" or "mustCall" in it, so its basically impossible to know that's what is failing. I figured it out after googling for what I thought was a weird v8 error message, and then when that didn't work, using git grep to find the source of the error message.

How does this relate to docs? Well, if the message can't include some useful hint as to what is wrong, then docing the current error string might help people who have read the docs.


Number of times `fn` should be called.
Returns a function that calls `fn`. If the returned function has not been called
exactly `expected` number of times when the test is complete, then the test will
Copy link
Contributor

Choose a reason for hiding this comment

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

We may want to specify that:

  1. It checks during process.on('exit')
  2. Wrapping exit handlers causes problems.

@emanuelbuholzer
Copy link
Contributor

When using this function the second parameter seems, even after looking at the source code multiple times, not clear enough for me. If you don't provide the number 1 it throws. I think the reason for this second parameter and for what it's used for should also be documented.

@Trott
Copy link
Member Author

Trott commented Dec 22, 2016

I think the reason for this second parameter and for what it's used for should also be documented.

That's exactly what this PR does. (Are you sure you are looking at the documentation change in this PR and not what is currently in master?)

If you don't provide the number 1 it throws.

That's incorrect.

The second parameter is called expected. That is currently documented.

If you do not provide a number, it defaults to 1. That is also currently documented.

This PR includes documentation that says:

If the returned function has not been called exactly expected number of times when the test is complete, then the test will fail.

That's the behavior you are seeing. I welcome a suggestion for better wording. Perhaps this?:

...then an AssertionError will be thrown and the test will fail.

@emanuelbuholzer
Copy link
Contributor

I'm sorry, I checked the code out again after your PR and probably mixed some things up. The wording is solid and makes it clearer now. Thanks for the help!

Trott added a commit to Trott/io.js that referenced this pull request Dec 23, 2016
PR-URL: nodejs#10390
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Julian Duque <julianduquej@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@Trott
Copy link
Member Author

Trott commented Dec 23, 2016

Landed in 9cfecce

@Trott Trott closed this Dec 23, 2016
evanlucas pushed a commit that referenced this pull request Jan 3, 2017
PR-URL: #10390
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Julian Duque <julianduquej@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
evanlucas pushed a commit that referenced this pull request Jan 4, 2017
PR-URL: #10390
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Julian Duque <julianduquej@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jan 23, 2017
PR-URL: #10390
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Julian Duque <julianduquej@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jan 24, 2017
PR-URL: #10390
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Julian Duque <julianduquej@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Jan 24, 2017
MylesBorins pushed a commit that referenced this pull request Jan 31, 2017
PR-URL: #10390
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Julian Duque <julianduquej@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@Trott Trott deleted the mustcall-doc branch January 13, 2022 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.