Skip to content

Commit 816309b

Browse files
committed
add test for equal wait and maxWait
1 parent 853b98a commit 816309b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

packages/replay/test/unit/util/debounce.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,20 @@ describe('debounce', () => {
240240
const returnValue = debouncedCallback.flush();
241241
expect(returnValue).toBe(undefined);
242242
});
243+
244+
it('should handle equal wait and maxWait values and only invoke func once', () => {
245+
const callback = jest.fn().mockReturnValue('foo');
246+
const debouncedCallback = debounce(callback, 100, { maxWait: 100 });
247+
248+
debouncedCallback();
249+
jest.advanceTimersByTime(100);
250+
251+
expect(callback).toHaveBeenCalledTimes(1);
252+
253+
const retval = debouncedCallback();
254+
expect(retval).toBe('foo');
255+
256+
jest.advanceTimersByTime(100);
257+
expect(callback).toHaveBeenCalledTimes(2);
258+
});
243259
});

0 commit comments

Comments
 (0)