From 7bd0c60ae9607e59169ff102102da5a7e26e3bb3 Mon Sep 17 00:00:00 2001 From: marco-ippolito Date: Fri, 5 Jan 2024 11:22:54 +0100 Subject: [PATCH] doc: improve subtests documentation --- doc/api/test.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/doc/api/test.md b/doc/api/test.md index 6d4725ba93c9fb..e805727a3a2930 100644 --- a/doc/api/test.md +++ b/doc/api/test.md @@ -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) => { @@ -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.