Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: clarify after and afterEach hooks execution #51523

Merged
merged 5 commits into from
Feb 3, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions doc/api/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,12 @@ describe('tests', async () => {
});
```

**Note:** The `after` hook is executed once after all the tests
in a test suite have completed, regardless of whether the tests
passed or failed. This hook is useful for performing cleanup tasks
or actions that should occur after the entire test suite has been run.
The `after` hook is guaranteed to run, even if tests within the suite fail.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Note:** The `after` hook is executed once after all the tests
in a test suite have completed, regardless of whether the tests
passed or failed. This hook is useful for performing cleanup tasks
or actions that should occur after the entire test suite has been run.
The `after` hook is guaranteed to run, even if tests within the suite fail.
**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 +1479,12 @@ added:
This function is used to create a hook running
after each subtest of the current test.

**Note:** The `afterEach` hook is executed after each individual test
in a test suite, regardless of whether the test passed or failed.
This hook is commonly used for cleaning up resources or resetting state
between tests. The `afterEach` hook is guaranteed to run after every test,
even if any of the tests fail.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Note:** The `afterEach` hook is executed after each individual test
in a test suite, regardless of whether the test passed or failed.
This hook is commonly used for cleaning up resources or resetting state
between tests. The `afterEach` hook is guaranteed to run after every test,
even if any of the tests fail.
**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
Loading