Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/evargast/mockrequestanimationframe
https://github.com/evargast/mockrequestanimationframe
Last synced: 23 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/evargast/mockrequestanimationframe
- Owner: evargast
- Created: 2020-08-05T23:13:49.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-10-06T18:51:15.000Z (about 2 years ago)
- Last Synced: 2024-04-24T04:30:04.563Z (8 months ago)
- Language: TypeScript
- Size: 526 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Mock Request Animation Frame
## Installation
```
yarn add -D mock-request-animation-frame
```or
```
npm i -D mock-request-animation-frame
```## Disclaimer
_These helper functions are intended to be used with Jest._
## Getting started
This module now comes with 2 helper functions! Specially designed for tests on components that use [Adobe React Spectrum](https://react-spectrum.adobe.com/react-spectrum/index.html).
1. **mockRequestAnimationFrame** - It will fully mock a [request animation frame](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame) (RAF). There are various components that leverage RAFs for rendering causing tests to break.
2. **mockClientWindow** - It will mock the height and width of the window object. Some components need dimensions for rendering, also breaking jest tests if not mocked.
You will have to call this helper functions in **each test file** that will encounter a RAF or needs window dimensions while executing.
Behind the scenes these functions use beforeEach, afterEach, beforeAll and afterAll thus it may be run at the top level of the file or at the top level of your `describe` statements see the examples below for more details.
### Examples
```javascript
// one-of-your-test-files
import { mockRequestAnimationFrame } from "mock-request-animation-frame";mockRequestAnimationFrame();
// Run your tests here
```or
```javascript
import { mockClientWindow } from "mock-request-animation-frame";describe("example test", () => {
mockClientWindow();// Run your tests here
});
```
##
Happy testing! 🔬