facebook/react · error · Error
Log is not empty. Assert on the log of yielded values before
Error message
Log is not empty. Assert on the log of yielded values before flushing additional work.
What it means
unstable_flushAll() is the strict assertion-path flush behind expect(Scheduler).toFlushAndYield([...]): before doing any work it requires the mock's yielded-value log (yieldedValues, populated by Scheduler.log()) to be empty. If a previous flush or setup left values unasserted, it throws 'Log is not empty. Assert on the log of yielded values before flushing additional work.' and performs no flush — the mock forces you to consume logged values between flushes.
Source
Thrown at packages/scheduler/src/forks/SchedulerMock.js:612
isFlushing = false;
}
} else {
return false;
}
}
function unstable_clearLog(): Array<mixed> {
if (yieldedValues === null) {
return [];
}
const values = yieldedValues;
yieldedValues = null;
return values;
}
function unstable_flushAll(): void {
if (yieldedValues !== null) {
throw new Error(
'Log is not empty. Assert on the log of yielded values before ' +
'flushing additional work.',
);
}
unstable_flushAllWithoutAsserting();
if (yieldedValues !== null) {
throw new Error(
'While flushing work, something yielded a value. Use an ' +
'assertion helper to assert on the log of yielded values, e.g. ' +
'expect(Scheduler).toFlushAndYield([...])',
);
}
}
function log(value: mixed): void {
// eslint-disable-next-line react-internal/no-production-logging
if (console.log.name === 'disabledLog' || disableYieldValue) {
// If console.log has been patched, we assume we're in renderView on GitHub (pinned to eafeac097b)
Solutions
- Assert the pending values first with expect(Scheduler).toFlushAndYield([...]) (or toFlushAndYieldThrough([...])) so the log is consumed.
- If you genuinely do not care about the stale values, drain them with Scheduler.unstable_clearLog() before the strict flush.
- Add Scheduler.unstable_reset() in beforeEach to stop tasks and log leaking between tests.
- Standardize on one assertion helper per flush instead of flushing twice in a row.
Example fix
// before
Scheduler.scheduleCallback(NormalPriority, () => Scheduler.log('a'));
Scheduler.unstable_flushAllWithoutAsserting(); // log now holds ['a']
Scheduler.unstable_flushAll(); // throws: Log is not empty
// after
Scheduler.scheduleCallback(NormalPriority, () => Scheduler.log('a'));
expect(Scheduler).toFlushAndYield(['a']); // asserts and clears the log
expect(Scheduler).toFlushAndYield([]); // now safe to flush again Defensive patterns
Strategy: validation
Validate before calling
// Drain (and optionally assert) pending values before a strict flush.
const pending = Scheduler.unstable_clearLog(); // returns and clears the log
if (pending.length > 0) {
// assert on `pending`, or deliberately discard it
}
Scheduler.unstable_flushAll(); // now safe Try / catch
try {
Scheduler.unstable_flushAll();
} catch (e) {
if (e instanceof Error && e.message.includes('Log is not empty')) {
Scheduler.unstable_clearLog();
Scheduler.unstable_flushAll(); // retry with a clean log
} else {
throw e;
}
} Prevention
- Assert yielded values after every flush that produces them (toFlushAndYield / toFlushAndYieldThrough).
- Reset the mock (Scheduler.unstable_reset()) in beforeEach to prevent log leakage between tests.
- Pick one flush style per test — do not mix strict and non-asserting helpers without asserting in between.
When it happens
Trigger: A prior flush helper (e.g. unstable_flushAllWithoutAsserting, or an assertion whose expectation was skipped) executed tasks that called Scheduler.log(value) and nothing consumed them; the test then calls Scheduler.unstable_flushAll() or toFlushAndYield again with a non-empty log.
Common situations: Mixing strict and non-strict flush helpers in one test; log leakage between tests because the mock was not reset in beforeEach; conditional logging branches that produce values the expectation did not cover.
Related errors
- While flushing work, something yielded a value. Use an asser
- Cannot reset while already flushing work.
- Already flushing work.
- react-dom/unstable_testing is not supported in React Server
- 361
AI-assisted analysis of facebook/react@eafeac097b (2026-08-21).
Data as JSON: /api/errors/c582dfa714acfa4f.
Report an issue: GitHub.