From 2d93630304aa88dcefad756fd6ed9cccca696f29 Mon Sep 17 00:00:00 2001 From: Robin Kehl Date: Wed, 8 Jan 2025 15:53:06 +0100 Subject: [PATCH 1/2] test: add failing test to debug #3665 --- packages/shared/watchDebounced/index.test.ts | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/shared/watchDebounced/index.test.ts b/packages/shared/watchDebounced/index.test.ts index b8317662fe5..9790aa41d92 100644 --- a/packages/shared/watchDebounced/index.test.ts +++ b/packages/shared/watchDebounced/index.test.ts @@ -44,4 +44,31 @@ describe('watchDebounced', () => { expect(cb).toHaveBeenCalledTimes(2) expect(cb).toHaveBeenCalledWith(4, 2, expect.anything()) }) + + it.todo('should work with constant changes over multiple maxWaits', async () => { + vi.useFakeTimers() + const num = ref(0) + const cb = vi.fn() + + const constantUpdateOverTime = async (ms: number) => { + for (let i = 0; i < ms; i++) { + num.value += 1 + await vi.advanceTimersByTimeAsync(1) + } + } + watchDebounced(num, cb, { debounce: 10, maxWait: 50 }) + expect(cb).toHaveBeenCalledTimes(0) + await constantUpdateOverTime(49) + expect(cb).toHaveBeenCalledTimes(0) + await constantUpdateOverTime(1) + expect(cb).toHaveBeenCalledTimes(1) + await constantUpdateOverTime(50) + expect(cb).toHaveBeenCalledTimes(2) + await constantUpdateOverTime(50) + + expect(cb).toHaveBeenCalledTimes(3) + expect(cb.mock.calls[0][0]).toBe(50) // or 51 + expect(cb.mock.calls[1][0]).toBe(100) // or 101 + expect(cb.mock.calls[2][0]).toBe(150) // or 151 + }) }) From 033b405b40942341d97068201a26aefcc1519655 Mon Sep 17 00:00:00 2001 From: OrbisK <37191683+OrbisK@users.noreply.github.com> Date: Sat, 11 Jan 2025 09:47:16 +0000 Subject: [PATCH 2/2] test: add `fails` variant --- packages/shared/watchDebounced/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared/watchDebounced/index.test.ts b/packages/shared/watchDebounced/index.test.ts index 9790aa41d92..7357f3fabcc 100644 --- a/packages/shared/watchDebounced/index.test.ts +++ b/packages/shared/watchDebounced/index.test.ts @@ -45,7 +45,7 @@ describe('watchDebounced', () => { expect(cb).toHaveBeenCalledWith(4, 2, expect.anything()) }) - it.todo('should work with constant changes over multiple maxWaits', async () => { + it.fails('should work with constant changes over multiple maxWaits', async () => { vi.useFakeTimers() const num = ref(0) const cb = vi.fn()