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
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.
39
+
40
+
## Usage notes
41
+
42
+
### With `react`
43
+
44
+
To avoid having to wrap everything in `act` calls, you can pass `act` to `configMocks`:
45
+
46
+
```jsx
47
+
import { configMocks } from'jsdom-testing-mocks';
48
+
import { act } from'...';
49
+
50
+
configMocks({ act });
51
+
```
52
+
53
+
It can be done in a setup file, or in a test file, before rendering the component.
54
+
55
+
### With `vitest`
56
+
57
+
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`.
58
+
59
+
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:
Mocks `matchMedia`, allows testing of component's behavior depending on the viewport description (supports all of the [Media Features](http://www.w3.org/TR/css3-mediaqueries/#media1)). `mockViewport` must be called before rendering the component
@@ -362,11 +408,11 @@ it('adds an element into the dom and fades it in', async () => {
362
408
});
363
409
```
364
410
365
-
###Using with fake timers
411
+
## Using with fake timers
366
412
367
413
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
414
369
-
###Current issues
415
+
## Current issues
370
416
371
417
- Needs more tests
372
418
@@ -389,5 +435,4 @@ It's perfectly usable with fake timers, except for the [issue with promises](htt
0 commit comments