Skip to content

Commit

Permalink
doc: clarify execution of after hook on test suite completion
Browse files Browse the repository at this point in the history
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: nodejs#50901
PR-URL: nodejs#51523
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
  • Loading branch information
ognjenjevremovic authored and rdw-msft committed Feb 9, 2024
1 parent 1efdaf2 commit 08bc1ce
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/api/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'));
Expand Down

0 comments on commit 08bc1ce

Please sign in to comment.