-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
nodejs-github-bot
merged 5 commits into
nodejs:main
from
ognjenjevremovic:docs/test-runner
Feb 3, 2024
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1a23c68
doc: clarify execution of `after` hook on test suite completion
ognjenjevremovic 19da229
doc: clarify execution of `afterEach` hook after each test
ognjenjevremovic 669ccaa
doc: improve clarity in after and afterEach hook documentation
ognjenjevremovic 8a1bedd
doc: improve clarity in after and afterEach hook documentation
ognjenjevremovic 4311384
doc: address line length linting error in documentation
ognjenjevremovic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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. | ||||||||||||||||
|
||||||||||||||||
## `beforeEach([fn][, options])` | ||||||||||||||||
|
||||||||||||||||
<!-- YAML | ||||||||||||||||
|
@@ -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. | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
|
||||||||||||||||
```js | ||||||||||||||||
describe('tests', async () => { | ||||||||||||||||
afterEach(() => console.log('finished running a test')); | ||||||||||||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.