doc: clarify execution of after hook on test suite completion

The `after` hook now explicitly mentions that it is executed once after
all the tests in a test suite have completed, regardless of whether the
tests passed or failed. This ensures that cleanup tasks or actions
specified in the after hook are guaranteed to run.

Refs: https://github.com/nodejs/node/issues/50901
PR-URL: https://github.com/nodejs/node/pull/51523
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
This commit is contained in:
Ognjen Jevremović authored and GitHub committed 2024-02-03 06:24:22 +00:00
1 parent 6f85b13c86
commit 9aa211edf5
1 file changed
+6
+6
View File
@@ -1420,6 +1420,9 @@ describe('tests', async () => {
});
```
**Note:** The `after` hook is guaranteed to run,
even if tests within the suite fail.
## `beforeEach([fn][, options])`
<!-- YAML
@@ -1473,6 +1476,9 @@ added:
This function is used to create a hook running
after each subtest of the current test.
**Note:** The `afterEach` hook is guaranteed to run after every test,
even if any of the tests fail.
```js
describe('tests', async () => {
afterEach(() => console.log('finished running a test'));