Looking for some recommendations on how to mock the .cancel
method in a debounce from lodash.
I have a function that is calling debounce
and then later utilizing the returned debounce value to call debouncedThing.cancel()
.
I am able to mock debounce
just fine in my tests except for when my function is called .cancel()
.
At the top of my unit tests I am currently doing:
jest.mock('lodash/debounce', () => fn => fn));
The above mock has worked fine except for in the place where I am calling debouncedThing.cancel()
. In those test, I get an error that debouncedThing.cancel()
is not a function.
Psuedo code of where I am using debounce looks like this:
const debouncedThing = debounce(
(myFunc, data) => myFunc(data),
DEBOUNCE_DELAY_TIME,
);
const otherFunc = () => {
/* omitted */
debouncedThing.cancel();
}