| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7d6c963 commit 08b5a2f
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1192,10 +1192,15 @@ assert.throws( | |||
| 1192 | 1192 | assert.throws( | |
| 1193 | 1193 | () => { | |
| 1194 | 1194 | const otherErr = new Error('Not found'); | |
| 1195 | - otherErr.code = 404; | ||
| 1195 | + // Copy all enumerable properties from `err` to `otherErr`. | ||
| 1196 | + for (const [key, value] of Object.entries(err)) { | ||
| 1197 | + otherErr[key] = value; | ||
| 1198 | + } | ||
| 1196 | 1199 | throw otherErr; | |
| 1197 | 1200 | }, | |
| 1198 | - err // This tests for `message`, `name` and `code`. | ||
| 1201 | + // The error's `message` and `name` properties will also be checked when using | ||
| 1202 | + // an error as validation object. | ||
| 1203 | + err | ||
| 1199 | 1204 | ); | |
| 1200 | 1205 | ``` | |
| 1201 | 1206 | ||
@@ -1282,11 +1287,9 @@ assert.throws(notThrowing, 'Second'); | |||
| 1282 | 1287 | // It does not throw because the error messages match. | |
| 1283 | 1288 | assert.throws(throwingSecond, /Second$/); | |
| 1284 | 1289 | ||
| 1285 | - // If the error message does not match, the error from within the function is | ||
| 1286 | - // not caught. | ||
| 1290 | + // If the error message does not match, an AssertionError is thrown. | ||
| 1287 | 1291 | assert.throws(throwingFirst, /Second$/); | |
| 1288 | - // Error: First | ||
| 1289 | - // at throwingFirst (repl:2:9) | ||
| 1292 | + // AssertionError [ERR_ASSERTION] | ||
| 1290 | 1293 | ``` | |
| 1291 | 1294 | ||
| 1292 | 1295 | Due to the confusing error-prone notation, avoid a string as the second | |
| Back | FazBrowse Home | New Git URL |
0 commit comments