@@ -446,6 +446,12 @@ This function is used to write TAP diagnostics to the output. Any diagnostic
446
446
information is included at the end of the test's results. This function does
447
447
not return a value.
448
448
449
+ ``` js
450
+ test (' top level test' , (t ) => {
451
+ t .diagnostic (' A diagnostic message' );
452
+ });
453
+ ```
454
+
449
455
### ` context.runOnly(shouldRunOnlyTests) `
450
456
451
457
<!-- YAML
@@ -459,6 +465,17 @@ have the `only` option set. Otherwise, all tests are run. If Node.js was not
459
465
started with the [ ` --test-only ` ] [ ] command-line option, this function is a
460
466
no-op.
461
467
468
+ ``` js
469
+ test (' top level test' , (t ) => {
470
+ // The test context can be set to run subtests with the 'only' option.
471
+ t .runOnly (true );
472
+ return Promise .all ([
473
+ t .test (' this subtest is now skipped' ),
474
+ t .test (' this subtest is run' , { only: true }),
475
+ ]);
476
+ });
477
+ ```
478
+
462
479
### ` context.skip([message]) `
463
480
464
481
<!-- YAML
@@ -472,6 +489,13 @@ This function causes the test's output to indicate the test as skipped. If
472
489
not terminate execution of the test function. This function does not return a
473
490
value.
474
491
492
+ ``` js
493
+ test (' top level test' , (t ) => {
494
+ // Make sure to return here as well if the test contains additional logic.
495
+ t .skip (' this is skipped' );
496
+ });
497
+ ```
498
+
475
499
### ` context.todo([message]) `
476
500
477
501
<!-- YAML
@@ -484,6 +508,13 @@ This function adds a `TODO` directive to the test's output. If `message` is
484
508
provided, it is included in the TAP output. Calling ` todo() ` does not terminate
485
509
execution of the test function. This function does not return a value.
486
510
511
+ ``` js
512
+ test (' top level test' , (t ) => {
513
+ // This test is marked as `TODO`
514
+ t .todo (' this is a todo' );
515
+ });
516
+ ```
517
+
487
518
### ` context.test([name][, options][, fn]) `
488
519
489
520
<!-- YAML
@@ -516,6 +547,18 @@ added: REPLACEME
516
547
This function is used to create subtests under the current test. This function
517
548
behaves in the same fashion as the top level [ ` test() ` ] [ ] function.
518
549
550
+ ``` js
551
+ test (' top level test' , async (t ) => {
552
+ await t .test (
553
+ ' This is a subtest' ,
554
+ { only: false , skip: false , concurrency: 1 , todo: false },
555
+ (t ) => {
556
+ assert .ok (' some relevant assertion here' );
557
+ }
558
+ );
559
+ });
560
+ ```
561
+
519
562
[ TAP ] : https://testanything.org/
520
563
[ `--test-only` ] : cli.md#--test-only
521
564
[ `--test` ] : cli.md#--test
0 commit comments