From 28664d6f6f4e2e68f60dbafb23b792fcb04789b6 Mon Sep 17 00:00:00 2001 From: gonzaloriestra <14979109+gonzaloriestra@users.noreply.github.com> Date: Sun, 6 Sep 2026 00:21:23 +0000 Subject: [PATCH 1/2] [Tests] Add unit tests for throttle utility --- .../src/public/common/function.test.ts | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/packages/cli-kit/src/public/common/function.test.ts b/packages/cli-kit/src/public/common/function.test.ts index 4a64391ed79..05df7d5f285 100644 --- a/packages/cli-kit/src/public/common/function.test.ts +++ b/packages/cli-kit/src/public/common/function.test.ts @@ -1,5 +1,5 @@ -import {debounce, memoize} from './function.js' -import {describe, test, expect} from 'vitest' +import {debounce, memoize, throttle} from './function.js' +import {afterEach, beforeEach, describe, expect, test, vi} from 'vitest' describe('memoize', () => { test('memoizes the function value', () => { @@ -35,3 +35,33 @@ describe('debounce', () => { expect(value).toEqual(1) }) }) + +describe('throttle', () => { + beforeEach(() => { + vi.useFakeTimers() + }) + + afterEach(() => { + vi.useRealTimers() + }) + + test('throttles function executions over time', () => { + // Given + let count = 0 + const throttled = throttle(() => { + count += 1 + }, 100) + + // When + throttled() + throttled() + throttled() + + // Then + expect(count).toBe(1) + + // Advance time past the wait interval + vi.advanceTimersByTime(100) + expect(count).toBe(2) + }) +}) From e7e709b1842a6e35580e6cd7c767caba00c880d3 Mon Sep 17 00:00:00 2001 From: gonzaloriestra <14979109+gonzaloriestra@users.noreply.github.com> Date: Sun, 6 Sep 2026 00:31:29 +0000 Subject: [PATCH 2/2] [Tests] Add unit tests for throttle utility