Skip to content

Commit 3247ed6

Browse files
committed
test(webview): assert the unmount timer count before advancing timers
What: move the vi.getTimerCount() check to directly after unmount() in the debounce unmount test, and document on LeadingEdgeDebounced<F> that suppressed trailing calls return undefined. Why: expired timers stop counting, so the old trailing assertion passed even with scrollToBottomSmooth.clear() removed from the unmount cleanup; the type also swallowed ReturnType<F> to undefined without saying so. Impact: the unmount cleanup is now pinned, and the helper's return contract is stated where callers read it.
1 parent 4a98d64 commit 3247ed6

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

‎webview-ui/src/hooks/__tests__/useScrollLifecycle.debounce.spec.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,15 @@ describe("useScrollLifecycle debounced scroll command", () => {
153153

154154
unmount()
155155

156+
// Checked before advancing: expired timers stop counting, so a removed
157+
// clear() would still pass the assertion at the end of this test.
158+
expect(vi.getTimerCount()).toBe(0)
159+
156160
act(() => {
157161
vi.advanceTimersByTime(SMOOTH_WINDOW_MS * 100)
158162
})
159163

160164
expect(smoothCalls(scrollToIndex)).toHaveLength(1)
161-
expect(vi.getTimerCount()).toBe(0)
162165
})
163166

164167
test("no smooth scroll is issued while the user browses history", () => {

‎webview-ui/src/utils/leadingEdgeDebounce.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
*
1010
* `.clear()` cancels the pending window; the next call after `.clear()` runs
1111
* immediately, matching the `debounce` package's `{ immediate: true }` mode.
12+
*
13+
* The return type is `undefined` on suppressed trailing calls: only the leading
14+
* call forwards `fn`'s result, so callers must not depend on a value there.
1215
*/
1316
export type LeadingEdgeDebounced<F extends (...args: never[]) => unknown> = F & {
1417
clear: () => void

0 commit comments

Comments
 (0)