Skip to content

Commit

Permalink
fix(debounce): cancel is not a function (#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
endv-bogdanb authored and dgonzalezr committed Sep 1, 2023
1 parent 8568f0e commit 645a25f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions packages/beeq/src/shared/utils/__tests__/debounce.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,13 @@ describe(debounce.name, () => {
expect(spy).toHaveBeenNthCalledWith(1, '0');
expect(spy).toHaveBeenLastCalledWith('test value');
});

it('should not fail if cancel is called but the function is not initialised yet', () => {
const spy = jest.fn<void, string[]>();

const fn = debounce(spy, 250, true);

expect(fn.cancel).not.toThrow();
expect(fn.cancel).not.toThrowError(new TypeError('cancel is not a function'));
});
});
2 changes: 1 addition & 1 deletion packages/beeq/src/shared/utils/debounce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const debounce = <TFunc extends TFunction>(func: TFunc, wait = 0, immedia

return Object.assign(debounceHandler, {
cancel: () => {
cancel();
cancel?.();
},
});
};

0 comments on commit 645a25f

Please sign in to comment.