@@ -13,11 +13,6 @@ code, most testing frameworks offer the option to replace the real timers in
13
13
your tests with fake ones. This has a side effect - when using fake timers in
14
14
your tests, _ all_ of the code inside your test uses fake timers.
15
15
16
- This becomes apparent when using [ ` user-event ` ] ( user-event/intro.mdx ) to test
17
- user interactions. Internally, it uses ` setTimeout ` to
18
- [ ` delay ` ] ( user-event/options.mdx#delay ) subsequent actions and allow
19
- asynchronous code to run between the inputs.
20
-
21
16
The common pattern to setup fake timers is usually within the ` beforeEach ` , for
22
17
example:
23
18
@@ -52,21 +47,10 @@ afterEach(() => {
52
47
})
53
48
```
54
49
55
- ## Using fake timers together with ` user-event `
56
-
57
- ` user-event ` internally uses ` setTimeout ` to delay subsequent actions. Using
58
- fake timers in such tests will cause timeouts, since the ` setTimeout ` callbacks
59
- do not get executed. In order to allow ` user-event ` to advance the fake timers,
60
- it is necessary to set [ ` advanceTimers ` ] ( user-event/options.mdx#advancetimers )
61
- option in ` userEvent.setup() ` :
62
-
63
- ``` js
64
- const user = userEvent .setup ({advanceTimers: jest .advanceTimersByTime })
65
- ```
66
-
67
- :::caution
50
+ :::note
68
51
69
- You may find suggestions to set ` delay: null ` in ` userEvent.setup() ` in order to
70
- solve this issue. That is not recommended, as it may cause unexpected behaviour.
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.
71
55
72
56
:::
0 commit comments