Skip to content

Commit

Permalink
test: Add test cases for debounce when it is already aborted
Browse files Browse the repository at this point in the history
  • Loading branch information
raon0211 committed Jun 14, 2024
1 parent 576b136 commit ac4039e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/function/debounce.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,24 @@ describe('debounce', () => {
expect(func).not.toHaveBeenCalled();
});

it('should not call the debounced function if it is already aborted by AbortSignal', async () => {
const controller = new AbortController();
const signal = controller.signal;

controller.abort();

const func = vi.fn();

const debounceMs = 50;
const debouncedFunc = debounce(func, debounceMs, { signal });

debouncedFunc();

await delay(debounceMs);

expect(func).not.toHaveBeenCalled();
})

it('should not add multiple abort event listeners', async () => {
const func = vi.fn();
const debounceMs = 100;
Expand Down

0 comments on commit ac4039e

Please sign in to comment.