flush-promises
Version:
Flush promises in tests
50 lines (35 loc) • 879 B
Markdown
[](https://travis-ci.org/kentor/flush-promises) [](https://www.npmjs.com/package/flush-promises)
Flush all pending resolved promise handlers. Useful in tests.
```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);
});
```
```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);
});
```