You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To avoid having to wrap everything in `act` calls, you can pass `act` to `configMocks`:
39
+
40
+
```jsx
41
+
import { configMocks } from'jsdom-testing-mocks';
42
+
import { act } from'...';
43
+
44
+
configMocks({ act });
45
+
```
46
+
47
+
It can be done in a setup file, or in a test file, before rendering the component.
48
+
49
+
### With `vitest`
50
+
51
+
Some mocks require lifecycle hooks to be defined on the global object. To make it work with vitest, you need to [enable globals in your config](https://vitest.dev/config/#globals). If you don't want to do that you can pass it manually using `configMocks`.
52
+
53
+
Also, if you're using fake timers, at the time of writing this, vitest doesn't enable faking `performance.now`, `requestAnimationFrame` and `cancelAnimationFrame` by default, so you need to do it manually:
We aim to support all major testing frameworks that support jsdom. Internally, there are no dependencies on any of them, so it's likely that it will work out of the box. Currently tested and confirmed to work with [jest](https://jestjs.io/) and [vitest](https://vitest.dev/). If you encounter any problems with other testing frameworks, please open an issue.
35
79
36
80
## Mock viewport
37
81
@@ -362,11 +406,11 @@ it('adds an element into the dom and fades it in', async () => {
362
406
});
363
407
```
364
408
365
-
###Using with fake timers
409
+
## Using with fake timers
366
410
367
411
It's perfectly usable with fake timers, except for the [issue with promises](https://github.com/facebook/jest/issues/2157). Also note that you would need to manually advance timers by the duration of the animation taking frame duration (which currently is set to 16ms in `jest`/`sinon.js`) into account. So if you, say, have an animation with a duration of `300ms`, you will need to advance your timers by the value that is at least the closest multiple of the frame duration, which in this case is `304ms` (`19` frames \*`16ms`). Otherwise the last frame may not fire and the animation won't finish.
368
412
369
-
###Current issues
413
+
## Current issues
370
414
371
415
- Needs more tests
372
416
@@ -389,5 +433,4 @@ It's perfectly usable with fake timers, except for the [issue with promises](htt
0 commit comments