Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

flush-promises

kentor829.4kMIT1.0.2TypeScript support: included

Flush promises in tests

async, await, flush, promise, promises, testing

readme

flush-promises

Build Status npm

Flush all pending resolved promise handlers. Useful in tests.

example with async/await

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

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