@@ -152,6 +152,42 @@ test('skip() method with message', t => {
152
152
})
153
153
```
154
154
155
+ ## ` describe ` /` it ` syntax
156
+
157
+ Running tests can also be done using ` describe ` to declare a suite
158
+ and ` it ` to declare a test.
159
+ A suite is used to organize and group related tests together.
160
+ ` it ` is an alias for ` test ` , except there is no test context passed,
161
+ since nesting is done using suites, as demonstrated in this example
162
+
163
+ ``` js
164
+ describe (' A thing' , () => {
165
+ it (' should work' , () => {
166
+ assert .strictEqual (1 , 1 );
167
+ });
168
+
169
+ it (' should be ok' , () => {
170
+ assert .strictEqual (2 , 2 );
171
+ });
172
+
173
+ describe (' a nested thing' , () => {
174
+ it (' should work' , () => {
175
+ assert .strictEqual (3 , 3 );
176
+ });
177
+ });
178
+ });
179
+ ```
180
+
181
+ ` describe ` and ` it ` are imported from the ` test ` module
182
+
183
+ ``` mjs
184
+ import { describe , it } from ' test' ;
185
+ ```
186
+
187
+ ``` cjs
188
+ const { describe , it } = require (' test' );
189
+ ```
190
+
155
191
### ` only ` tests
156
192
157
193
If ` node--test ` is started with the ` --test-only ` command-line option, it is
@@ -303,7 +339,7 @@ internally.
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 ` 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 ` 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
An instance of ` TestContext ` is passed to each test function in order to
@@ -394,7 +483,7 @@ execution of the test function. This function does not return a value.
394
483
- ` todo ` {boolean|string} If truthy, the test marked as ` TODO ` . If a string
395
484
is provided, that string is displayed in the test results as the reason why
396
485
the test is ` TODO ` . ** Default:** ` false ` .
397
- - ` fn ` {Function|AsyncFunction} The function under test. This first argument
486
+ - ` fn ` {Function|AsyncFunction} The function under test. The first argument
398
487
to this function is a [ ` TestContext ` ] [ ] object. If the test uses callbacks,
399
488
the callback function is passed as the second argument. ** Default:** A no-op
400
489
function.
@@ -406,6 +495,8 @@ behaves in the same fashion as the top level [`test()`][] function.
406
495
[ tap ] : https://testanything.org/
407
496
[ `testcontext` ] : #class-testcontext
408
497
[ `test()` ] : #testname-options-fn
498
+ [ describe options ] : #describename-options-fn
499
+ [ it options ] : #testname-options-fn
409
500
[ test runner execution model ] : #test-runner-execution-model
410
501
411
502
## License
0 commit comments