@@ -148,6 +148,42 @@ test('skip() method with message', (t) => {
148
148
});
149
149
```
150
150
151
+ ## ` describe ` /` it ` syntax
152
+
153
+ Running tests can also be done using ` describe ` to declare a suite
154
+ and ` it ` to declare a test.
155
+ A suite is used to organize and group related tests together.
156
+ ` it ` is an alias for ` test ` , except there is no test context passed,
157
+ since nesting is done using suites, as demonstrated in this example
158
+
159
+ ``` js
160
+ describe (' A thing' , () => {
161
+ it (' should work' , () => {
162
+ assert .strictEqual (1 , 1 );
163
+ });
164
+
165
+ it (' should be ok' , () => {
166
+ assert .strictEqual (2 , 2 );
167
+ });
168
+
169
+ describe (' a nested thing' , () => {
170
+ it (' should work' , () => {
171
+ assert .strictEqual (3 , 3 );
172
+ });
173
+ });
174
+ });
175
+ ```
176
+
177
+ ` describe ` and ` it ` are imported from the ` node:test ` module
178
+
179
+ ``` mjs
180
+ import { describe , it } from ' node:test' ;
181
+ ```
182
+
183
+ ``` cjs
184
+ const { describe , it } = require (' node:test' );
185
+ ```
186
+
151
187
### ` only ` tests
152
188
153
189
If Node.js is started with the [ ` --test-only ` ] [ ] command-line option, it is
@@ -303,7 +339,7 @@ added: v18.0.0
303
339
* ` todo ` {boolean|string} If truthy, the test marked as ` TODO ` . If a string
304
340
is provided, that string is displayed in the test results as the reason why
305
341
the test is ` TODO ` . ** Default:** ` false ` .
306
- * ` fn ` {Function|AsyncFunction} The function under test. This first argument
342
+ * ` fn ` {Function|AsyncFunction} The function under test. The first argument
307
343
to this function is a [ ` TestContext ` ] [ ] object. If the test uses callbacks,
308
344
the callback function is passed as the second argument. ** Default:** A no-op
309
345
function.
@@ -335,6 +371,59 @@ test('top level test', async (t) => {
335
371
});
336
372
```
337
373
374
+ ## ` describe([name][, options][, fn]) `
375
+
376
+ * ` name ` {string} The name of the suite, which is displayed when reporting test
377
+ results. ** Default:** The ` name ` property of ` fn ` , or ` '<anonymous>' ` if ` fn `
378
+ does not have a name.
379
+ * ` options ` {Object} Configuration options for the suite.
380
+ supports the same options as ` test([name][, options][, fn]) `
381
+ * ` fn ` {Function} The function under suite.
382
+ a synchronous function declaring all subtests and subsuites.
383
+ ** Default:** A no-op function.
384
+ * Returns: ` undefined ` .
385
+
386
+ The ` describe() ` function imported from the ` node:test ` module. Each
387
+ invocation of this function results in the creation of a Subtest
388
+ and a test point in the TAP output.
389
+ After invocation of top level ` describe ` functions,
390
+ all top level tests and suites will execute
391
+
392
+ ## ` describe.skip([name][, options][, fn]) `
393
+
394
+ Shorthand for skipping a suite, same as [ ` describe([name], { skip: true }[, fn]) ` ] [ describe options ] .
395
+
396
+ ## ` describe.todo([name][, options][, fn]) `
397
+
398
+ Shorthand for marking a suite as ` TODO ` , same as
399
+ [ ` describe([name], { todo: true }[, fn]) ` ] [ describe options ] .
400
+
401
+ ## ` it([name][, options][, fn]) `
402
+
403
+ * ` name ` {string} The name of the test, which is displayed when reporting test
404
+ results. ** Default:** The ` name ` property of ` fn ` , or ` '<anonymous>' ` if ` fn `
405
+ does not have a name.
406
+ * ` options ` {Object} Configuration options for the suite.
407
+ supports the same options as ` test([name][, options][, fn]) ` .
408
+ * ` fn ` {Function|AsyncFunction} The function under test.
409
+ If the test uses callbacks, the callback function is passed as an argument.
410
+ ** Default:** A no-op function.
411
+ * Returns: ` undefined ` .
412
+
413
+ The ` it() ` function is the value imported from the ` node:test ` module.
414
+ Each invocation of this function results in the creation of a test point in the
415
+ TAP output.
416
+
417
+ ## ` it.skip([name][, options][, fn]) `
418
+
419
+ Shorthand for skipping a test,
420
+ same as [ ` it([name], { skip: true }[, fn]) ` ] [ it options ] .
421
+
422
+ ## ` it.todo([name][, options][, fn]) `
423
+
424
+ Shorthand for marking a test as ` TODO ` ,
425
+ same as [ ` it([name], { todo: true }[, fn]) ` ] [ it options ] .
426
+
338
427
## Class: ` TestContext `
339
428
340
429
<!-- YAML
@@ -449,7 +538,7 @@ added: v18.0.0
449
538
* ` todo ` {boolean|string} If truthy, the test marked as ` TODO ` . If a string
450
539
is provided, that string is displayed in the test results as the reason why
451
540
the test is ` TODO ` . ** Default:** ` false ` .
452
- * ` fn ` {Function|AsyncFunction} The function under test. This first argument
541
+ * ` fn ` {Function|AsyncFunction} The function under test. The first argument
453
542
to this function is a [ ` TestContext ` ] [ ] object. If the test uses callbacks,
454
543
the callback function is passed as the second argument. ** Default:** A no-op
455
544
function.
@@ -475,4 +564,6 @@ test('top level test', async (t) => {
475
564
[ `--test` ] : cli.md#--test
476
565
[ `TestContext` ] : #class-testcontext
477
566
[ `test()` ] : #testname-options-fn
567
+ [ describe options ] : #describename-options-fn
568
+ [ it options ] : #testname-options-fn
478
569
[ test runner execution model ] : #test-runner-execution-model
0 commit comments