tape: t.throws() expected and msg parameters don't seem to behave as they are described.
Hello. I am a little confused by the documentation for t.throws(), as it seems to be discrepant in two ways with the behavior I experience:
-
The documentation says that the
expectedparameter, if present, must be a RegExp or Function. But when I pass in a string, and execute a test, the test seems to complete without issue (see below for code). Furthermore, the string passed as theexpectedparameter is printed to the console, seemingly as the test description. Nor does theexpectedstring match the string representation of the exception (as described in the documentation). Here is a screenshot of a passing test–something similar occurs for a failing test. Why is that? What am I misunderstanding? -
The documentation mentions that the third parameter–
msg–is an optional description of the assertion. So when/where exactly is this string used? I’ve executed two tests—one passing and one failing (see below for code). In neither case is themsgparameter printed to the console (see pass screenshot here; see fail screenshot here).
My passing test. To change it to a failing test, comment out the throw line.
t.throws(
() => {
throw 'Error message.'// Comment this line to force a failing test.
},
'Message 1',
'Message 2'
)
Thanks in advance.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (9 by maintainers)
OK I had a better look and believe I see the issue–good old user error 😃 In my testing, I was using Tape v4.13, and it appears that the code you highlighted was added after that version. Once I tested with the latest version of Tape, I can indeed confirm the expected behavior. Sorry for the confustion there!
Let me add the example to the README now and submit a PR. Stand by…
OK cool. Sorry, needing a few more days on this–something came up at work.
OK thanks for that. Understood that
extrais a fourth optional parameter that can be passed tot.throws(). I have to be honest, I still have a few questions about it. But how about for now I ignore that, and do this with the README. I’ll edit thet.throws()section of the README to indicate only:expectedparameter can be a regex, function. or a “validation object” (as you mentioned above).t.throws()if theexpectedparameter is not one of the above three values.I’ll omit any mention of
extrafor now. Then I can submit a pull request to you. At that time, if you want me to edit what I’ve written in the README, or add info aboutextra, we can discuss in the pull request, and I can add commits later if need be before you merge. Would that be OK?