# mock-request-animation-frame

> Helper function for Jest + RAF

Latest version **2.1.2** (published 2022-10-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install mock-request-animation-frame
pnpm add mock-request-animation-frame
yarn add mock-request-animation-frame
bun add mock-request-animation-frame
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.2 |
| Published | 2022-10-06 |
| First published | 2020-08-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Eduardo Vargas |
| Maintainers | eduardo-vargas |
| Keywords | react, jest, RAF, request animation frame, mock, animation, frame, Adobe, spectrum |

## Links

- npm: https://www.npmjs.com/package/mock-request-animation-frame
- Repository: https://github.com/evargast/MockRequestAnimationFrame
- Homepage: https://github.com/evargast/MockRequestAnimationFrame#readme
- Issues: https://github.com/evargast/MockRequestAnimationFrame/issues
- npm.io page: https://npm.io/package/mock-request-animation-frame

## Dependencies (1)

- [jest](https://npm.io/package/jest.md) 23 - 27

## Alternatives

- [@luma.gl/experimental](https://npm.io/package/@luma.gl/experimental.md) — 77.1K weekly downloads
- [persona-harness](https://npm.io/package/persona-harness.md) — 4.7K weekly downloads
- [@tsparticles/effect-bubble](https://npm.io/package/@tsparticles/effect-bubble.md) — 4.6K weekly downloads
- [f3d](https://npm.io/package/f3d.md) — 730 weekly downloads
- [spark-html-motion](https://npm.io/package/spark-html-motion.md) — 298 weekly downloads

## Recent versions

- 2.1.2 (latest) — 2022-10-06
- 2.1.1 — 2022-10-06
- 2.1.0 — 2022-10-06
- 2.0.0 — 2022-10-06
- 1.1.1 — 2022-10-06
- 1.1.0 — 2022-10-06
- 1.0.5 — 2022-06-02
- 1.0.4 — 2020-09-17
- 1.0.3 — 2020-08-24
- 1.0.2 — 2020-08-24
- 1.0.1 — 2020-08-07

## README

# Mock Request Animation Frame

<a href="https://www.npmjs.com/package/mock-request-animation-frame">
    <img alt="npm" src="https://img.shields.io/npm/v/mock-request-animation-frame.svg?style=flat-square">
</a>

<a href="https://www.npmjs.com/package/mock-request-animation-frame">
    <img alt="npm" src="https://img.shields.io/npm/dt/mock-request-animation-frame?style=flat-square">
</a>

## 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
});
```

&nbsp;
&nbsp;
&nbsp;
&nbsp;

## <div align="center"> Happy testing! 🔬</div>

---
_Source: https://npm.io/package/mock-request-animation-frame · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
