Skip to content

test(throttle): assert the trailing call actually fires - #365

Merged
nedtwigg merged 1 commit into
mainfrom
test/throttle-trailing-assertion
Aug 15, 2026
Merged

test(throttle): assert the trailing call actually fires#365
nedtwigg merged 1 commit into
mainfrom
test/throttle-trailing-assertion

Conversation

@dormouse-bot

Copy link
Copy Markdown
Collaborator

Problem

The "coalesces a burst" test in throttle.test.ts asserts a final trailing call fires after the burst settles, but the check was ineffective:

const total = fn.mock.calls.length;
expect(total).toBeGreaterThan(duringBurst - 1); // == total >= duringBurst

total is a mock call count taken after duringBurst, and call counts only ever grow, so total >= duringBurst is trivially true. If throttleTrailing regressed and fired no trailing call after the burst, total would equal duringBurst and the assertion would still pass — the test's stated purpose ("a final trailing call fits the resting geometry") was never actually verified.

Fix

Tighten to expect(total).toBeGreaterThan(duringBurst) so exactly-one-more fire after settling is required. With the current implementation the burst leaves a trailing call pending on the last frame, so one more fire lands during the +300ms settle and the strict assertion passes; a regression that dropped the trailing call would now fail. Test-only change — no production code touched.

The burst test's post-settle assertion was `toBeGreaterThan(duringBurst - 1)`,
i.e. `>= duringBurst`. Since mock call counts only grow, that holds even if no
trailing call fired after the burst — the test's stated purpose (one final
trailing fire) was never verified. Tighten to `> duringBurst` so a regression
that drops the trailing call fails the test.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying mouseterm with  Cloudflare Pages  Cloudflare Pages

Latest commit: a8ca469
Status: ✅  Deploy successful!
Preview URL: https://5f3679da.mouseterm.pages.dev
Branch Preview URL: https://test-throttle-trailing-asser.mouseterm.pages.dev

View logs

@nedtwigg
nedtwigg merged commit 8a5850d into main Aug 15, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants