Registry / testing / flush-microtasks

flush-microtasks

JSON →
library1.0.1jsnpmunverified

Utility to flush the microtask queue (e.g., pending Promises) by returning a thenable that resolves when the queue is empty. Version 1.0.1 is stable, with no recent releases. It is a minimal, focused library extracted from React's enqueueTask implementation, ideal for testing or scenarios requiring deterministic microtask execution. Differentiates by providing a simple, dependency-free function without side effects.

npm install flush-microtasks
INSTALL
IMPORT
SIG · FLUSH-MICROTASKS
F
flush-microtasks
testingjavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

flushMicroTasks
import { flushMicroTasks } from 'flush-microtasks'
const flushMicroTasks = require('flush-microtasks')
Package is ESM-only and does not support CommonJS require. Use named import.
flushMicroTasks (default import attempt)
import { flushMicroTasks } from 'flush-microtasks'
import flushMicroTasks from 'flush-microtasks'
The package has only a named export, no default export.
TypeScript type
import type { flushMicroTasks } from 'flush-microtasks'
import { flushMicroTasks } from 'flush-microtasks' // for types only
The package does not export types separately; use `typeof` if needed.

Demonstrates using flushMicroTasks to wait for pending microtasks (Promise callbacks) to complete before proceeding.

import { flushMicroTasks } from 'flush-microtasks'; async function example() { console.log('Before flush'); Promise.resolve().then(() => console.log('Microtask')); await flushMicroTasks(); console.log('After flush'); } example(); // Output: "Before flush" -> "Microtask" -> "After flush"
Debug
Known issues
gotchaflushMicroTasks() only resolves after the current microtask queue is empty. If new microtasks are added during flush, they will not be waited for.
fix
Call flushMicroTasks() again or use a loop if you need to drain continuously added microtasks.
affects: >=1.0.0
breakingThe export is named, not default. Attempting a default import will result in undefined.
fix
Use named import: import { flushMicroTasks } from 'flush-microtasks'
affects: >=1.0.0
gotchaThe function is not exported as a CommonJS module; require() will not work.
fix
Use ES module import syntax.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: flushMicroTasks is not a function
Default import used instead of named import.
fix
Change to: import { flushMicroTasks } from 'flush-microtasks'
Error: Cannot find module 'flush-microtasks'
Trying to use require() in an ESM-only package.
fix
Use import syntax or add "type": "module" to package.json.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
flush-microtasks — npm install flush-microtasks · libregistry