Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kentor/flush-promises
Flush all queued resolved promise handlers
https://github.com/kentor/flush-promises
async await promises testing
Last synced: about 14 hours ago
JSON representation
Flush all queued resolved promise handlers
- Host: GitHub
- URL: https://github.com/kentor/flush-promises
- Owner: kentor
- License: mit
- Created: 2017-05-14T01:18:11.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-05-10T15:38:46.000Z (over 3 years ago)
- Last Synced: 2024-10-29T10:45:20.720Z (9 days ago)
- Topics: async, await, promises, testing
- Language: JavaScript
- Homepage:
- Size: 53.7 KB
- Stars: 194
- Watchers: 3
- Forks: 6
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# flush-promises
[![Build Status](https://travis-ci.org/kentor/flush-promises.svg)](https://travis-ci.org/kentor/flush-promises) [![npm](https://img.shields.io/npm/v/flush-promises.svg)](https://www.npmjs.com/package/flush-promises)
Flush all pending resolved promise handlers. Useful in tests.
## example with async/await
```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);
});
```## TypeScript
```ts
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);
});
```