kentor / flush-promises

Flush all queued resolved promise handlers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Flush all queued resolved promise handlers

License:MIT License


Languages

Language:JavaScript 100.0%