UNPKG

@cc-heart/utils

Version:

🔧 javascript common tools collection

32 lines (28 loc) • 740 B
import { useDebounce } from '../../../hooks' describe('useDebounce', () => { beforeAll(() => { jest.useFakeTimers() }) it('should be called only once when ', () => { const fn = jest.fn() const debounce = useDebounce(fn) debounce() debounce() debounce() jest.runAllTimers() expect(fn.mock.calls.length).toBe(1) expect(fn).toHaveBeenCalledTimes(1) }) it('should be called every when execution is delayed', async () => { const fn = jest.fn() const debounce = useDebounce(fn, 500) debounce() jest.runAllTimers() debounce() jest.runAllTimers() debounce() jest.runAllTimers() expect(fn.mock.calls.length).toBe(3) expect(fn).toHaveBeenCalledTimes(3) }) })