Flush all queued resolved promise handlers
Switch branches/tags
Nothing to show
Clone or download
kentor bump to 1.0.2
fixes the typescript def
Latest commit 46f5877 Nov 1, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.npmignore init May 14, 2017
.travis.yml init May 14, 2017
LICENSE init May 14, 2017
README.md Add missing semicolon Oct 30, 2018
index.d.ts Complete Type Definitions for TypeScript Oct 30, 2018
index.js init May 14, 2017
jest.config.js init May 14, 2017
package.json bump to 1.0.2 Nov 1, 2018
test.js init May 14, 2017
yarn.lock init May 14, 2017

README.md

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