Skip to content

Commit

Permalink
doc: improve subtests documentation
Browse files Browse the repository at this point in the history
PR-URL: #51379
Fixes: #51359
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Moshe Atlow <[email protected]>
  • Loading branch information
marco-ippolito authored and richardlau committed Mar 25, 2024
1 parent 8610207 commit f301f82
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions doc/api/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,12 @@ If any tests fail, the process exit code is set to `1`.

## Subtests

The test context's `test()` method allows subtests to be created. This method
behaves identically to the top level `test()` function. The following example
demonstrates the creation of a top level test with two subtests.
The test context's `test()` method allows subtests to be created.
It allows you to structure your tests in a hierarchical manner,
where you can create nested tests within a larger test.
This method behaves identically to the top level `test()` function.
The following example demonstrates the creation of a
top level test with two subtests.

```js
test('top level test', async (t) => {
Expand All @@ -121,9 +124,13 @@ test('top level test', async (t) => {
});
```

> **Note:** `beforeEach` and `afterEach` hooks are triggered
> between each subtest execution.
In this example, `await` is used to ensure that both subtests have completed.
This is necessary because parent tests do not wait for their subtests to
complete. Any subtests that are still outstanding when their parent finishes
complete, unlike tests created with the `describe` and `it` syntax.
Any subtests that are still outstanding when their parent finishes
are cancelled and treated as failures. Any subtest failures cause the parent
test to fail.

Expand Down

0 comments on commit f301f82

Please sign in to comment.