# flush-promises

> Flush promises in tests

Latest version **1.0.2** (published 2018-11-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install flush-promises
pnpm add flush-promises
yarn add flush-promises
bun add flush-promises
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2018-11-01 |
| First published | 2017-05-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 195 |
| Author | Kenneth Chung |
| Maintainers | kentor |
| Keywords | async, await, flush, promise, promises, testing |

## Links

- npm: https://www.npmjs.com/package/flush-promises
- Repository: https://github.com/kentor/flush-promises
- Issues: https://github.com/kentor/flush-promises/issues
- npm.io page: https://npm.io/package/flush-promises

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2018-11-01
- 1.0.1 — 2018-10-30
- 1.0.0 — 2017-05-14

## README

# flush-promises

[![Build Status](https://travis-ci.org/kentor/flush-promises.svg)](https://travis-ci.org/kentor/flush-promises) [![npm](https://img.shields.io/npm/v/flush-promises.svg)](https://www.npmjs.com/package/flush-promises)

Flush all pending resolved promise handlers. Useful in tests.

## example with async/await

```js
const flushPromises = require('flush-promises');

test('flushPromises', async () => {
  let a;
  let b;

  Promise.resolve().then(() => {
    a = 1;
  }).then(() => {
    b = 2;
  })

  await flushPromises();

  expect(a).toBe(1);
  expect(b).toBe(2);
});
```

## TypeScript

```ts
import * as flushPromises from "flush-promises";

test("flushPromises", async () => {
  let a;
  let b;
 
  Promise.resolve().then(() => {
    a = 1;
  }).then(() => {
    b = 2;
  });
 
  await flushPromises();
 
  expect(a).toBe(1);
  expect(b).toBe(2);
});
```

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