flush-promises
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.2
    288,613
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.2
    288,613
  • 1.0.1
    11
  • 1.0.0
    331

Package Sidebar

Install

npm i flush-promises

Weekly Downloads

288,955

Version

1.0.2

License

MIT

Unpacked Size

3.33 kB

Total Files

8

Last publish

Collaborators

  • kentor