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:

  1. The documentation says that the expected parameter, 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 the expected parameter is printed to the console, seemingly as the test description. Nor does the expected string 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?

  2. 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 the msg parameter 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)

Most upvoted comments

https://github.com/substack/tape/blob/master/lib/test.js#L617-L630 is the code that’s supposed to be handling it. In other words, it should be returning false if the code values aren’t deeply strictly equal.

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 extra is a fourth optional parameter that can be passed to t.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 the t.throws() section of the README to indicate only:

  1. The expected parameter can be a regex, function. or a “validation object” (as you mentioned above).
  2. The behavior of t.throws() if the expected parameter is not one of the above three values.

I’ll omit any mention of extra for 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 about extra, we can discuss in the pull request, and I can add commits later if need be before you merge. Would that be OK?