| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 06c367e commit cbaf120
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -357,6 +357,12 @@ This function is used to write TAP diagnostics to the output. Any diagnostic | |||
| 357 | 357 | information is included at the end of the test's results. This function does | |
| 358 | 358 | not return a value. | |
| 359 | 359 | ||
| 360 | + ```js | ||
| 361 | + test('top level test', (t) => { | ||
| 362 | + t.diagnostic('A diagnostic message'); | ||
| 363 | + }); | ||
| 364 | + ``` | ||
| 365 | + | ||
| 360 | 366 | ### `context.runOnly(shouldRunOnlyTests)` | |
| 361 | 367 | ||
| 362 | 368 | <!-- YAML | |
@@ -370,6 +376,17 @@ have the `only` option set. Otherwise, all tests are run. If Node.js was not | |||
| 370 | 376 | started with the [`--test-only`][] command-line option, this function is a | |
| 371 | 377 | no-op. | |
| 372 | 378 | ||
| 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 | + | ||
| 373 | 390 | ### `context.skip([message])` | |
| 374 | 391 | ||
| 375 | 392 | <!-- YAML | |
@@ -383,6 +400,13 @@ This function causes the test's output to indicate the test as skipped. If | |||
| 383 | 400 | not terminate execution of the test function. This function does not return a | |
| 384 | 401 | value. | |
| 385 | 402 | ||
| 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 | + | ||
| 386 | 410 | ### `context.todo([message])` | |
| 387 | 411 | ||
| 388 | 412 | <!-- YAML | |
@@ -395,6 +419,13 @@ This function adds a `TODO` directive to the test's output. If `message` is | |||
| 395 | 419 | provided, it is included in the TAP output. Calling `todo()` does not terminate | |
| 396 | 420 | execution of the test function. This function does not return a value. | |
| 397 | 421 | ||
| 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 | + | ||
| 398 | 429 | ### `context.test([name][, options][, fn])` | |
| 399 | 430 | ||
| 400 | 431 | <!-- YAML | |
@@ -427,6 +458,18 @@ added: v18.0.0 | |||
| 427 | 458 | This function is used to create subtests under the current test. This function | |
| 428 | 459 | behaves in the same fashion as the top level [`test()`][] function. | |
| 429 | 460 | ||
| 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 | + | ||
| 430 | 473 | [TAP]: https://testanything.org/ | |
| 431 | 474 | [`--test-only`]: cli.md#--test-only | |
| 432 | 475 | [`--test`]: cli.md#--test | |
| Back | FazBrowse Home | New Git URL |
0 commit comments