From fe65996790937e842d5c2692aed050b77abaff70 Mon Sep 17 00:00:00 2001 From: Livia Medeiros <74449973+LiviaMedeiros@users.noreply.github.com> Date: Thu, 28 Apr 2022 05:50:19 +0800 Subject: [PATCH] doc: clarify guide on testing internal errors PR-URL: https://github.com/nodejs/node/pull/42813 Reviewed-By: Antoine du Hamel Reviewed-By: Darshan Sen Reviewed-By: Mohammed Keyvanzadeh Reviewed-By: Michael Dawson Reviewed-By: Colin Ihrig Reviewed-By: Akhil Marsonya --- doc/contributing/writing-tests.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/doc/contributing/writing-tests.md b/doc/contributing/writing-tests.md index 6241cb68c9624f..c24526f0139843 100644 --- a/doc/contributing/writing-tests.md +++ b/doc/contributing/writing-tests.md @@ -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