| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e681abe commit c5c1dc5
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,11 +37,44 @@ Tests strict non-equality, as determined by the strict not equal operator ( `!== | |||
| 37 | 37 | ||
| 38 | 38 | ### assert.throws(block, [error], [message]) | |
| 39 | 39 | ||
| 40 | - Expects `block` to throw an error. | ||
| 40 | + Expects `block` to throw an error. `error` can be constructor, regexp or | ||
| 41 | + validation function. | ||
| 42 | + | ||
| 43 | + Validate instanceof using constructor: | ||
| 44 | + | ||
| 45 | + assert.throws( | ||
| 46 | + function() { | ||
| 47 | + throw new Error("Wrong value"); | ||
| 48 | + }, | ||
| 49 | + Error | ||
| 50 | + ); | ||
| 51 | + | ||
| 52 | + Validate error message using RegExp: | ||
| 53 | + | ||
| 54 | + assert.throws( | ||
| 55 | + function() { | ||
| 56 | + throw new Error("Wrong value"); | ||
| 57 | + }, | ||
| 58 | + /value/ | ||
| 59 | + ); | ||
| 60 | + | ||
| 61 | + Custom error validation: | ||
| 62 | + | ||
| 63 | + assert.throws( | ||
| 64 | + function() { | ||
| 65 | + throw new Error("Wrong value"); | ||
| 66 | + }, | ||
| 67 | + function(err) { | ||
| 68 | + if ( !(err instanceof Error) || !/value/.test(err) ) { | ||
| 69 | + return false; | ||
| 70 | + } | ||
| 71 | + }, | ||
| 72 | + "unexpected error" | ||
| 73 | + ); | ||
| 41 | 74 | ||
| 42 | 75 | ### assert.doesNotThrow(block, [error], [message]) | |
| 43 | 76 | ||
| 44 | - Expects `block` not to throw an error. | ||
| 77 | + Expects `block` not to throw an error, see assert.throws for details. | ||
| 45 | 78 | ||
| 46 | 79 | ### assert.ifError(value) | |
| 47 | 80 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments