| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -256,19 +256,20 @@ If the values are not equal, an `AssertionError` is thrown with a `message` | |||
| 256 | 256 | property set equal to the value of the `message` parameter. If the `message` | |
| 257 | 257 | parameter is undefined, a default error message is assigned. | |
| 258 | 258 | ||
| 259 | - ## assert.fail(message) | ||
| 259 | + ## assert.fail([message]) | ||
| 260 | 260 | ## assert.fail(actual, expected, message, operator) | |
| 261 | 261 | <!-- YAML | |
| 262 | 262 | added: v0.1.21 | |
| 263 | 263 | --> | |
| 264 | 264 | * `actual` {any} | |
| 265 | 265 | * `expected` {any} | |
| 266 | - * `message` {any} | ||
| 266 | + * `message` {any} (default: 'Failed') | ||
| 267 | 267 | * `operator` {string} (default: '!=') | |
| 268 | 268 | ||
| 269 | 269 | Throws an `AssertionError`. If `message` is falsy, the error message is set as | |
| 270 | 270 | the values of `actual` and `expected` separated by the provided `operator`. | |
| 271 | 271 | Otherwise, the error message is the value of `message`. | |
| 272 | + If no arguments are provided at all, a default message will be used instead. | ||
| 272 | 273 | ||
| 273 | 274 | ```js | |
| 274 | 275 | const assert = require('assert'); | |
@@ -284,6 +285,9 @@ assert.fail('boom'); | |||
| 284 | 285 | ||
| 285 | 286 | assert.fail('a', 'b'); | |
| 286 | 287 | // AssertionError: 'a' != 'b' | |
| 288 | + | ||
| 289 | + assert.fail(); | ||
| 290 | + // AssertionError: Failed | ||
| 287 | 291 | ``` | |
| 288 | 292 | ||
| 289 | 293 | ## assert.ifError(value) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,8 +52,13 @@ const assert = module.exports = ok; | |||
| 52 | 52 | // display purposes. | |
| 53 | 53 | ||
| 54 | 54 | function fail(actual, expected, message, operator, stackStartFunction) { | |
| 55 | - if (arguments.length === 1) | ||
| 55 | + if (arguments.length === 0) { | ||
| 56 | + message = 'Failed'; | ||
| 57 | + } | ||
| 58 | + if (arguments.length === 1) { | ||
| 56 | 59 | message = actual; | |
| 60 | + actual = undefined; | ||
| 61 | + } | ||
| 57 | 62 | if (arguments.length === 2) | |
| 58 | 63 | operator = '!='; | |
| 59 | 64 | const errors = lazyErrors(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,7 @@ assert.throws( | |||
| 8 | 8 | common.expectsError({ | |
| 9 | 9 | code: 'ERR_ASSERTION', | |
| 10 | 10 | type: assert.AssertionError, | |
| 11 | - message: 'undefined undefined undefined' | ||
| 11 | + message: 'Failed' | ||
| 12 | 12 | }) | |
| 13 | 13 | ); | |
| 14 | 14 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments