doc: clarify guide on testing internal errors

PR-URL: https://github.com/nodejs/node/pull/42813
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Akhil Marsonya <akhil.marsonya27@gmail.com>
pull/42893/head
Livia Medeiros 2022-04-28 05:50:19 +08:00 committed by GitHub
parent 8cbc39068c
commit fc485a9cbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 0 deletions

View File

@ -312,6 +312,18 @@ assert.throws(
);
```
In the case of internal errors, prefer checking only the `code` property:
```js
assert.throws(
() => {
throw new ERR_FS_FILE_TOO_LARGE(`${sizeKiB} Kb`);
},
{ code: 'ERR_FS_FILE_TOO_LARGE' }
// Do not include message: /^File size ([0-9]+ Kb) is greater than 2 GiB$/
);
```
### Console output
Output written by tests to stdout or stderr, such as with `console.log()` or