# flush-promises **Repository Path**: ArkTSCentralRepository/flush-promises ## Basic Information - **Project Name**: flush-promises - **Description**: flush-promises 是一个工具库,用于清除所有待处理的已解决 Promise 处理程序,常用于测试中确保异步代码执行完成。 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-11-21 - **Last Updated**: 2024-11-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # flush-promises 基于[flush-promises](https://www.npmjs.com/package/flush-promises)原库1.0.2版本进行适配, 所有功能代码已经转换为`ArkTS`文件 ## Install ```sh ohpm install flush-promises ``` Flush all pending resolved promise handlers. Useful in tests. ## example with async/await ```js 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); }); ``` ## TypeScript ```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); }); ```