Permalink
Browse files

Docs: Align assert.throws() and assert.rejects() docs (#1265)

  • Loading branch information...
Arkni authored and platinumazure committed Feb 11, 2018
1 parent 1d6f27b commit 7e7bb7e8c19355fd1b1c72737cc6263afbd00d2b
Showing with 8 additions and 3 deletions.
  1. +8 −3 docs/assert/throws.md
View
@@ -6,22 +6,27 @@ categories:
- assert
---
-## `throws( blockFn, expected [, message ] )`
+## `throws( blockFn[, expectedMatcher][, message ] )`
Test if a callback throws an exception, and optionally compare the thrown error.
| name | description |
|--------------------|--------------------------------------|
| `blockFn` (function) | Function to execute |
-| `expected` | Expected Error |
+| `expectedMatcher` | Expected error matcher |
| `message` (string) | A short description of the assertion |
### Description
When testing code that is expected to throw an exception based on a specific set of circumstances, use `assert.throws()` to catch the error object for testing and comparison.
-The `expected` argument can be an Error Object (instance), an Error Function (constructor), a RegExp that matches (or partially matches) the String representation, or a callback Function that must return `true` to pass the assertion check.
+The `expectedMatcher` argument can be:
+
+* An Error object
+* An Error constructor to use ala `errorValue instanceof expectedMatcher`
+* A RegExp that matches (or partially matches) the String representation
+* A callback Function that must return `true` to pass the assertion check.
> In very few environments, like Closure Compiler, `throws` is considered a reserved word and will cause an error. For that case, an alias is bundled called `raises`. It has the same signature and behaviour, just a different name.

0 comments on commit 7e7bb7e

Please sign in to comment.