@@ -357,6 +357,12 @@ This function is used to write TAP diagnostics to the output. Any diagnostic
357357information is included at the end of the test's results. This function does
358358not return a value.
359359
360+ ``` js
361+ test (' top level test' , (t ) => {
362+ t .diagnostic (' A diagnostic message' );
363+ });
364+ ```
365+
360366### ` context.runOnly(shouldRunOnlyTests) `
361367
362368<!-- YAML
@@ -370,6 +376,17 @@ have the `only` option set. Otherwise, all tests are run. If Node.js was not
370376started with the [ ` --test-only ` ] [ ] command-line option, this function is a
371377no-op.
372378
379+ ``` js
380+ test (' top level test' , (t ) => {
381+ // The test context can be set to run subtests with the 'only' option.
382+ t .runOnly (true );
383+ return Promise .all ([
384+ t .test (' this subtest is now skipped' ),
385+ t .test (' this subtest is run' , { only: true }),
386+ ]);
387+ });
388+ ```
389+
373390### ` context.skip([message]) `
374391
375392<!-- YAML
@@ -383,6 +400,13 @@ This function causes the test's output to indicate the test as skipped. If
383400not terminate execution of the test function. This function does not return a
384401value.
385402
403+ ``` js
404+ test (' top level test' , (t ) => {
405+ // Make sure to return here as well if the test contains additional logic.
406+ t .skip (' this is skipped' );
407+ });
408+ ```
409+
386410### ` context.todo([message]) `
387411
388412<!-- YAML
@@ -395,6 +419,13 @@ This function adds a `TODO` directive to the test's output. If `message` is
395419provided, it is included in the TAP output. Calling ` todo() ` does not terminate
396420execution of the test function. This function does not return a value.
397421
422+ ``` js
423+ test (' top level test' , (t ) => {
424+ // This test is marked as `TODO`
425+ t .todo (' this is a todo' );
426+ });
427+ ```
428+
398429### ` context.test([name][, options][, fn]) `
399430
400431<!-- YAML
@@ -427,6 +458,18 @@ added: v18.0.0
427458This function is used to create subtests under the current test. This function
428459behaves in the same fashion as the top level [ ` test() ` ] [ ] function.
429460
461+ ``` js
462+ test (' top level test' , async (t ) => {
463+ await t .test (
464+ ' This is a subtest' ,
465+ { only: false , skip: false , concurrency: 1 , todo: false },
466+ (t ) => {
467+ assert .ok (' some relevant assertion here' );
468+ }
469+ );
470+ });
471+ ```
472+
430473[ TAP ] : https://testanything.org/
431474[ `--test-only` ] : cli.md#--test-only
432475[ `--test` ] : cli.md#--test
0 commit comments