Skip to content

Commit cdcda47

Browse files
authored
Merge branch 'main' into feat/fix-layout-shift
2 parents b09f2a2 + 167be7b commit cdcda47

File tree

6 files changed

+60
-22
lines changed

6 files changed

+60
-22
lines changed

.all-contributorsrc

+18
Original file line numberDiff line numberDiff line change
@@ -2646,6 +2646,24 @@
26462646
"contributions": [
26472647
"doc"
26482648
]
2649+
},
2650+
{
2651+
"login": "domnantas",
2652+
"name": "Domantas Petrauskas",
2653+
"avatar_url": "https://avatars.githubusercontent.com/u/51953549?v=4",
2654+
"profile": "https://domnantas.lt",
2655+
"contributions": [
2656+
"doc"
2657+
]
2658+
},
2659+
{
2660+
"login": "Efim-Kapliy",
2661+
"name": "Efim",
2662+
"avatar_url": "https://avatars.githubusercontent.com/u/126895483?v=4",
2663+
"profile": "https://portfolio.edkt.ru",
2664+
"contributions": [
2665+
"doc"
2666+
]
26492667
}
26502668
],
26512669
"contributorsPerLine": 7,

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,12 @@ Thanks goes to these wonderful people
506506
</tr>
507507
<tr>
508508
<td align="center" valign="top" width="14.28%"><a href="https://github.com/smk267"><img src="https://avatars.githubusercontent.com/u/88115182?v=4?s=100" width="100px;" alt="smk267"/><br /><sub><b>smk267</b></sub></a><br /><a href="#infra-smk267" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
509-
<td align="center" valign="top" width="14.28%"><a href="https://github.com/vadimshvetsov"><img src="https://avatars.githubusercontent.com/u/16336572?v=4?s=100" width="100px;" alt="Vadim Shvetsov"/><br /><sub><b>Vadim Shvetsov</b></sub></a><br /><a href="https://github.com/testing-library/testing-library-docs/commits?author=vadimshvetsov" title="Documentation">📖</a></td>
510509
<td align="center" valign="top" width="14.28%"><a href="https://www.dylangordon.co.nz/"><img src="https://avatars.githubusercontent.com/u/3656794?v=4?s=100" width="100px;" alt="Dylan Gordon"/><br /><sub><b>Dylan Gordon</b></sub></a><br /><a href="https://github.com/testing-library/testing-library-docs/commits?author=agentdylan" title="Documentation">📖</a></td>
511510
<td align="center" valign="top" width="14.28%"><a href="https://michael.cousins.io"><img src="https://avatars.githubusercontent.com/u/2963448?v=4?s=100" width="100px;" alt="Michael Cousins"/><br /><sub><b>Michael Cousins</b></sub></a><br /><a href="https://github.com/testing-library/testing-library-docs/commits?author=mcous" title="Documentation">📖</a> <a href="https://github.com/testing-library/testing-library-docs/pulls?q=is%3Apr+reviewed-by%3Amcous" title="Reviewed Pull Requests">👀</a></td>
512511
<td align="center" valign="top" width="14.28%"><a href="https://kettanaito.com"><img src="https://avatars.githubusercontent.com/u/14984911?v=4?s=100" width="100px;" alt="Artem Zakharchenko"/><br /><sub><b>Artem Zakharchenko</b></sub></a><br /><a href="https://github.com/testing-library/testing-library-docs/commits?author=kettanaito" title="Documentation">📖</a></td>
512+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/vadimshvetsov"><img src="https://avatars.githubusercontent.com/u/16336572?v=4?s=100" width="100px;" alt="Vadim Shvetsov"/><br /><sub><b>Vadim Shvetsov</b></sub></a><br /><a href="https://github.com/testing-library/testing-library-docs/commits?author=vadimshvetsov" title="Documentation">📖</a></td>
513+
<td align="center" valign="top" width="14.28%"><a href="https://domnantas.lt"><img src="https://avatars.githubusercontent.com/u/51953549?v=4?s=100" width="100px;" alt="Domantas Petrauskas"/><br /><sub><b>Domantas Petrauskas</b></sub></a><br /><a href="https://github.com/testing-library/testing-library-docs/commits?author=domnantas" title="Documentation">📖</a></td>
514+
<td align="center" valign="top" width="14.28%"><a href="https://portfolio.edkt.ru"><img src="https://avatars.githubusercontent.com/u/126895483?v=4?s=100" width="100px;" alt="Efim"/><br /><sub><b>Efim</b></sub></a><br /><a href="https://github.com/testing-library/testing-library-docs/commits?author=Efim-Kapliy" title="Documentation">📖</a></td>
513515
</tr>
514516
</tbody>
515517
</table>

docs/guides-using-fake-timers.mdx

+14-11
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ flaky.
1010

1111
To solve these problems, or if you need to rely on specific timestamps in your
1212
code, most testing frameworks offer the option to replace the real timers in
13-
your tests with fake ones. This should be used sporadically and not on a regular
14-
basis since using it contains some overhead.
15-
16-
When using fake timers in your tests, all of the code inside your test uses fake
17-
timers.
13+
your tests with fake ones. This has a side effect - when using fake timers in
14+
your tests, _all_ of the code inside your test uses fake timers.
1815

1916
The common pattern to setup fake timers is usually within the `beforeEach`, for
2017
example:
@@ -26,12 +23,10 @@ beforeEach(() => {
2623
})
2724
```
2825

29-
When using fake timers, you need to remember to restore the timers after your
30-
test runs.
31-
32-
The main reason to do that is to prevent 3rd party libraries running after your
33-
test finishes (e.g cleanup functions), from being coupled to your fake timers
34-
and use real timers instead.
26+
Since fake timers are mocking native timer functions, it is necessary to restore
27+
the timers after your test runs, just like regular mocks. This prevents fake
28+
timers leaking into other test cases and cleanup functions, where real timers
29+
are expected.
3530

3631
For that you usually call `useRealTimers` in `afterEach`.
3732

@@ -51,3 +46,11 @@ afterEach(() => {
5146
jest.useRealTimers()
5247
})
5348
```
49+
50+
:::note
51+
52+
Combining fake timers with `user-event` may cause test timeouts. Refer to
53+
[`advanceTimers`](user-event/options.mdx#advancetimers) option to prevent this
54+
issue.
55+
56+
:::

docs/react-testing-library/example-intro.mdx

+2
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ test('loads and displays greeting', async () => {
6666
See the following sections for a detailed breakdown of the test
6767

6868
:::note
69+
6970
We recommend using the
7071
[Mock Service Worker (MSW)](https://github.com/mswjs/msw) library to
7172
declaratively mock API communication in your tests instead of stubbing
7273
`window.fetch`, or relying on third-party adapters.
74+
7375
:::
7476

7577
```jsx title="__tests__/fetch.test.jsx"

docs/react-testing-library/setup.mdx

+8-8
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ make your test util file accessible without using relative paths.
3131
The example below sets up data providers using the [`wrapper`](api.mdx#wrapper)
3232
option to `render`.
3333

34-
<Tabs groupId="test-utils" defaultValue="jsx" values={[ {label: 'JavaScript',
35-
value: 'jsx'}, {label: 'TypeScript', value: 'tsx'}, ]}>
34+
<Tabs groupId="test-utils" defaultValue="js" values={[ {label: 'JavaScript',
35+
value: 'js'}, {label: 'TypeScript', value: 'ts'}, ]}>
3636

37-
<TabItem value="jsx">
37+
<TabItem value="js">
3838

3939
```diff title="my-component.test.jsx"
4040
- import { render, fireEvent } from '@testing-library/react';
@@ -70,7 +70,7 @@ export {customRender as render}
7070

7171
</TabItem>
7272

73-
<TabItem value="tsx">
73+
<TabItem value="ts">
7474

7575
```diff title="my-component.test.tsx"
7676
- import { render, fireEvent } from '@testing-library/react';
@@ -250,10 +250,10 @@ passing a [`queries`](api.mdx#render-options) option.
250250
If you want to add custom queries globally, you can do this by defining your
251251
customized `render`, `screen` and `within` methods:
252252

253-
<Tabs groupId="test-utils" defaultValue="jsx" values={[ {label: 'JavaScript',
254-
value: 'jsx'}, {label: 'TypeScript', value: 'tsx'}, ]}>
253+
<Tabs groupId="test-utils" defaultValue="js" values={[ {label: 'JavaScript',
254+
value: 'js'}, {label: 'TypeScript', value: 'ts'}, ]}>
255255

256-
<TabItem value="jsx">
256+
<TabItem value="js">
257257

258258
```js title="test-utils.js"
259259
import {render, queries, within} from '@testing-library/react'
@@ -278,7 +278,7 @@ export {customScreen as screen, customWithin as within, customRender as render}
278278

279279
</TabItem>
280280

281-
<TabItem value="tsx">
281+
<TabItem value="ts">
282282

283283
```ts title="test-utils.ts"
284284
import {render, queries, within, RenderOptions} from '@testing-library/react'

docs/user-event/options.mdx

+15-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,21 @@ can be applied per [`setup()`](setup.mdx).
88

99
### advanceTimers
1010

11-
If you are using fake timers, you need to advance your timers when we internally
12-
[delay](#delay) subsequent code.
11+
`user-event` adds a [delay](#delay) between some subsequent inputs. When using
12+
[fake timers](/guides-using-fake-timers.mdx) it is necessary to set this option
13+
to your test runner's time advancement function. For example:
14+
15+
```js
16+
const user = userEvent.setup({advanceTimers: jest.advanceTimersByTime})
17+
```
18+
19+
:::caution
20+
21+
You may find suggestions to set `delay: null` to prevent test timeouts when
22+
using fake timers. That is not recommended, as it may cause unexpected
23+
behaviour. Starting from v14.1, we suggest using `advanceTimers` option instead.
24+
25+
:::
1326

1427
```ts
1528
(delay: number) => Promise<void> | void

0 commit comments

Comments
 (0)