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

Question: Why does t.doesNotThrow have three arguments? #334

Closed
des-des opened this issue Dec 5, 2016 · 3 comments
Closed

Question: Why does t.doesNotThrow have three arguments? #334

des-des opened this issue Dec 5, 2016 · 3 comments
Labels

Comments

@des-des
Copy link

des-des commented Dec 5, 2016

I do not understand why t.doesNotThrow(fn, expected, msg) has three arguments. It seems like the second argument, expected, is actually used as the message: https://github.com/substack/tape/blob/master/lib/test.js#L476.

Why doesn't the function just have the signature t.doesNotThrow(fn, message)?

@ljharb
Copy link
Collaborator

ljharb commented Dec 5, 2016

It's an if - if you pass an error instance, it checks the type of the error as well.

It's meant to mirror the assert API.

@ljharb ljharb added the question label Dec 5, 2016
@des-des
Copy link
Author

des-des commented Dec 28, 2016

@ljharb

I do not see how we can check type of error which has not been thrown. Sorry, I might be missing something.

It seems the in the API for assert doesNotThrow only takes two arguments https://www.npmjs.com/package/assert#assertdoesnotthrowblock-message. But might be looking in the wrong place.

@ljharb
Copy link
Collaborator

ljharb commented Dec 28, 2016

@des-des that package is not the core module assert, it's something else that nobody can ever actually require in node. You're looking for https://nodejs.org/api/assert.html#assert_assert_doesnotthrow_block_error_message which also explains what the argument is used for. "does not throw a TypeError" is not the same as "does not throw anything at all" - something that throws a RangeError, for example, fails the latter but passes the former.

@ljharb ljharb closed this as completed Dec 28, 2016
axelpale added a commit to axelpale/tape that referenced this issue Nov 25, 2018
To prevent issues like tape-testing#334, here is a proposal to clarify the purpose of the second argument. My own first reaction to the second argument was like "Whaaat, the docs cannot be right. Even the mere word 'expected' is against the purpose of the assertion. How we can expect something that is not thrown. The argument cannot have any meaning." Then I browsed through the issues, found tape-testing#334 and then it became clear.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants