Skip to content

Commit 84a1290

Browse files
authored
docs: use admonitions in Global APIs docs of v29 (#13198)
1 parent 7baa452 commit 84a1290

File tree

1 file changed

+43
-35
lines changed

1 file changed

+43
-35
lines changed

website/versioned_docs/version-29.0/GlobalAPI.md

+43-35
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import TOCInline from '@theme/TOCInline';
1919

2020
Runs a function after all the tests in this file have completed. If the function returns a promise or is a generator, Jest waits for that promise to resolve before continuing.
2121

22-
Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait before aborting. _Note: The default timeout is 5 seconds._
22+
Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait before aborting. The default timeout is 5 seconds.
2323

2424
This is often useful if you want to clean up some global setup state that is shared across tests.
2525

@@ -59,7 +59,7 @@ If you want to run some cleanup after every test instead of after all tests, use
5959

6060
Runs a function after each one of the tests in this file completes. If the function returns a promise or is a generator, Jest waits for that promise to resolve before continuing.
6161

62-
Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait before aborting. _Note: The default timeout is 5 seconds._
62+
Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait before aborting. The default timeout is 5 seconds.
6363

6464
This is often useful if you want to clean up some temporary state that is created by each test.
6565

@@ -99,7 +99,7 @@ If you want to run some cleanup just once, after all of the tests run, use `afte
9999

100100
Runs a function before any of the tests in this file run. If the function returns a promise or is a generator, Jest waits for that promise to resolve before running tests.
101101

102-
Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait before aborting. _Note: The default timeout is 5 seconds._
102+
Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait before aborting. The default timeout is 5 seconds.
103103

104104
This is often useful if you want to set up some global state that will be used by many tests.
105105

@@ -135,7 +135,7 @@ If you want to run something before every test instead of before any test runs,
135135

136136
Runs a function before each of the tests in this file runs. If the function returns a promise or is a generator, Jest waits for that promise to resolve before running the test.
137137

138-
Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait before aborting. _Note: The default timeout is 5 seconds._
138+
Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait before aborting. The default timeout is 5 seconds.
139139

140140
This is often useful if you want to reset some global state that will be used by many tests.
141141

@@ -232,8 +232,8 @@ Use `describe.each` if you keep duplicating the same test suites with different
232232

233233
#### 1. `describe.each(table)(name, fn, timeout)`
234234

235-
- `table`: `Array` of Arrays with the arguments that are passed into the `fn` for each row.
236-
- _Note_ If you pass in a 1D array of primitives, internally it will be mapped to a table i.e. `[1, 2, 3] -> [[1], [2], [3]]`
235+
- `table`: `Array` of Arrays with the arguments that are passed into the `fn` for each row. If you pass in a 1D array of primitives, internally it will be mapped to a table i.e. `[1, 2, 3] -> [[1], [2], [3]]`.
236+
237237
- `name`: `String` the title of the test suite.
238238
- Generate unique test titles by positionally injecting parameters with [`printf` formatting](https://nodejs.org/api/util.html#util_util_format_format_args):
239239
- `%p` - [pretty-format](https://www.npmjs.com/package/pretty-format).
@@ -250,7 +250,7 @@ Use `describe.each` if you keep duplicating the same test suites with different
250250
- You can use `$#` to inject the index of the test case
251251
- You cannot use `$variable` with the `printf` formatting except for `%%`
252252
- `fn`: `Function` the suite of tests to be ran, this is the function that will receive the parameters in each row as function arguments.
253-
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. _Note: The default timeout is 5 seconds._
253+
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. The default timeout is 5 seconds.
254254

255255
Example:
256256

@@ -302,7 +302,7 @@ describe.each([
302302
- `name`: `String` the title of the test suite, use `$variable` to inject test data into the suite title from the tagged template expressions, and `$#` for the index of the row.
303303
- To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value`
304304
- `fn`: `Function` the suite of tests to be ran, this is the function that will receive the test data object.
305-
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. _Note: The default timeout is 5 seconds._
305+
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. The default timeout is 5 seconds.
306306

307307
Example:
308308

@@ -475,11 +475,9 @@ test('did not rain', () => {
475475
});
476476
```
477477

478-
The first argument is the test name; the second argument is a function that contains the expectations to test. The third argument (optional) is `timeout` (in milliseconds) for specifying how long to wait before aborting. _Note: The default timeout is 5 seconds._
479-
480-
> Note: If a **promise is returned** from `test`, Jest will wait for the promise to resolve before letting the test complete. Jest will also wait if you **provide an argument to the test function**, usually called `done`. This could be handy when you want to test callbacks. See how to test async code [here](TestingAsyncCode.md#callbacks).
478+
The first argument is the test name; the second argument is a function that contains the expectations to test. The third argument (optional) is `timeout` (in milliseconds) for specifying how long to wait before aborting. The default timeout is 5 seconds.
481479

482-
For example, let's say `fetchBeverageList()` returns a promise that is supposed to resolve to a list that has `lemon` in it. You can test this with:
480+
If a **promise is returned** from `test`, Jest will wait for the promise to resolve before letting the test complete. For example, let's say `fetchBeverageList()` returns a promise that is supposed to resolve to a list that has `lemon` in it. You can test this with:
483481

484482
```js
485483
test('has lemon in it', () => {
@@ -489,19 +487,29 @@ test('has lemon in it', () => {
489487
});
490488
```
491489

492-
Even though the call to `test` will return right away, the test doesn't complete until the promise resolves as well.
490+
Even though the call to `test` will return right away, the test doesn't complete until the promise resolves. For more details, see [Testing Asynchronous Code](TestingAsyncCode.md) page.
491+
492+
:::tip
493+
494+
Jest will also wait if you **provide an argument to the test function**, usually called `done`. This could be handy when you want to test [callbacks](TestingAsyncCode.md#callbacks).
495+
496+
:::
493497

494498
### `test.concurrent(name, fn, timeout)`
495499

496500
Also under the alias: `it.concurrent(name, fn, timeout)`
497501

498-
Use `test.concurrent` if you want the test to run concurrently.
502+
:::caution
499503

500-
> Note: `test.concurrent` is considered experimental - see [here](https://github.com/facebook/jest/labels/Area%3A%20Concurrent) for details on missing features and other issues
504+
`test.concurrent` is considered experimental - see [here](https://github.com/facebook/jest/labels/Area%3A%20Concurrent) for details on missing features and other issues.
501505

502-
The first argument is the test name; the second argument is an asynchronous function that contains the expectations to test. The third argument (optional) is `timeout` (in milliseconds) for specifying how long to wait before aborting. _Note: The default timeout is 5 seconds._
506+
:::
503507

504-
```
508+
Use `test.concurrent` if you want the test to run concurrently.
509+
510+
The first argument is the test name; the second argument is an asynchronous function that contains the expectations to test. The third argument (optional) is `timeout` (in milliseconds) for specifying how long to wait before aborting. The default timeout is 5 seconds.
511+
512+
```js
505513
test.concurrent('addition of 2 numbers', async () => {
506514
expect(5 + 3).toBe(8);
507515
});
@@ -511,7 +519,11 @@ test.concurrent('subtraction 2 numbers', async () => {
511519
});
512520
```
513521

514-
> Note: Use `maxConcurrency` in configuration to prevents Jest from executing more than the specified amount of tests at the same time
522+
:::tip
523+
524+
Use [`maxConcurrency`](Configuration.md/#maxconcurrency-number) configuration option to prevent Jest from executing more than the specified amount of tests at the same time.
525+
526+
:::
515527

516528
### `test.concurrent.each(table)(name, fn, timeout)`
517529

@@ -523,8 +535,7 @@ Use `test.concurrent.each` if you keep duplicating the same test with different
523535

524536
#### 1. `test.concurrent.each(table)(name, fn, timeout)`
525537

526-
- `table`: `Array` of Arrays with the arguments that are passed into the test `fn` for each row.
527-
- _Note_ If you pass in a 1D array of primitives, internally it will be mapped to a table i.e. `[1, 2, 3] -> [[1], [2], [3]]`
538+
- `table`: `Array` of Arrays with the arguments that are passed into the test `fn` for each row. If you pass in a 1D array of primitives, internally it will be mapped to a table i.e. `[1, 2, 3] -> [[1], [2], [3]]`
528539
- `name`: `String` the title of the test block.
529540
- Generate unique test titles by positionally injecting parameters with [`printf` formatting](https://nodejs.org/api/util.html#util_util_format_format_args):
530541
- `%p` - [pretty-format](https://www.npmjs.com/package/pretty-format).
@@ -537,7 +548,7 @@ Use `test.concurrent.each` if you keep duplicating the same test with different
537548
- `%#` - Index of the test case.
538549
- `%%` - single percent sign ('%'). This does not consume an argument.
539550
- `fn`: `Function` the test to be ran, this is the function that will receive the parameters in each row as function arguments, **this will have to be an asynchronous function**.
540-
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. _Note: The default timeout is 5 seconds._
551+
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. The default timeout is 5 seconds.
541552

542553
Example:
543554

@@ -559,7 +570,7 @@ test.concurrent.each([
559570
- `name`: `String` the title of the test, use `$variable` to inject test data into the test title from the tagged template expressions.
560571
- To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value`
561572
- `fn`: `Function` the test to be ran, this is the function that will receive the test data object, **this will have to be an asynchronous function**.
562-
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. _Note: The default timeout is 5 seconds._
573+
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. The default timeout is 5 seconds.
563574

564575
Example:
565576

@@ -666,8 +677,7 @@ Use `test.each` if you keep duplicating the same test with different data. `test
666677

667678
#### 1. `test.each(table)(name, fn, timeout)`
668679

669-
- `table`: `Array` of Arrays with the arguments that are passed into the test `fn` for each row.
670-
- _Note_ If you pass in a 1D array of primitives, internally it will be mapped to a table i.e. `[1, 2, 3] -> [[1], [2], [3]]`
680+
- `table`: `Array` of Arrays with the arguments that are passed into the test `fn` for each row. If you pass in a 1D array of primitives, internally it will be mapped to a table i.e. `[1, 2, 3] -> [[1], [2], [3]]`
671681
- `name`: `String` the title of the test block.
672682
- Generate unique test titles by positionally injecting parameters with [`printf` formatting](https://nodejs.org/api/util.html#util_util_format_format_args):
673683
- `%p` - [pretty-format](https://www.npmjs.com/package/pretty-format).
@@ -684,7 +694,7 @@ Use `test.each` if you keep duplicating the same test with different data. `test
684694
- You can use `$#` to inject the index of the test case
685695
- You cannot use `$variable` with the `printf` formatting except for `%%`
686696
- `fn`: `Function` the test to be ran, this is the function that will receive the parameters in each row as function arguments.
687-
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. _Note: The default timeout is 5 seconds._
697+
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. The default timeout is 5 seconds.
688698

689699
Example:
690700

@@ -716,7 +726,7 @@ test.each([
716726
- `name`: `String` the title of the test, use `$variable` to inject test data into the test title from the tagged template expressions.
717727
- To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value`
718728
- `fn`: `Function` the test to be ran, this is the function that will receive the test data object.
719-
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. _Note: The default timeout is 5 seconds._
729+
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. The default timeout is 5 seconds.
720730

721731
Example:
722732

@@ -817,7 +827,7 @@ Also under the aliases: `it.only(name, fn, timeout)`, and `fit(name, fn, timeout
817827

818828
When you are debugging a large test file, you will often only want to run a subset of tests. You can use `.only` to specify which tests are the only ones you want to run in that test file.
819829

820-
Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait before aborting. _Note: The default timeout is 5 seconds._
830+
Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait before aborting. The default timeout is 5 seconds.
821831

822832
For example, let's say you had these tests:
823833

@@ -945,20 +955,18 @@ Also under the alias: `it.todo(name)`
945955

946956
Use `test.todo` when you are planning on writing tests. These tests will be highlighted in the summary output at the end so you know how many tests you still need todo.
947957

948-
_Note_: If you supply a test callback function then the `test.todo` will throw an error. If you have already implemented the test and it is broken and you do not want it to run, then use `test.skip` instead.
949-
950-
#### API
951-
952-
- `name`: `String` the title of the test plan.
953-
954-
Example:
955-
956958
```js
957959
const add = (a, b) => a + b;
958960

959961
test.todo('add should be associative');
960962
```
961963

964+
:::tip
965+
966+
`test.todo` will throw an error, if you will pass it a test callback function. Use [`test.skip`](#testskipname-fn) instead, if you already implemented the test, but do not want it to run.
967+
968+
:::
969+
962970
## TypeScript Usage
963971

964972
:::info

0 commit comments

Comments
 (0)