Skip to content

Commit 84edc56

Browse files
committed
Document how to test code that uses p-queue with Jest fake timers
Closes #193
1 parent 54fd7f3 commit 84edc56

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

readme.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,23 @@ for await (const result of pMapIterable(
739739
}
740740
```
741741

742+
#### How do I test code that uses `p-queue` with Jest fake timers?
743+
744+
Jest fake timers don't work well with `p-queue` because it uses `queueMicrotask` internally.
745+
746+
Workaround:
747+
748+
```js
749+
const flushPromises = () => new Promise(resolve => setImmediate(resolve));
750+
751+
jest.useFakeTimers();
752+
753+
// ... your test code ...
754+
755+
await jest.runAllTimersAsync();
756+
await flushPromises();
757+
```
758+
742759
## Maintainers
743760

744761
- [Sindre Sorhus](https://github.com/sindresorhus)

0 commit comments

Comments
 (0)