I have this function
import _ from 'underscore';
const configMap = {};
export function someFunctionName(someValue, dispatch, reduxAction) {
if (!configMap[someValue]) {
configMap[someValue] = _.debounce(
(someValue) => dispatch(reduxAction(someValue)),
1000,
);
}
return configMap[someValue];
}
with jest tests:
const dispatchMock = jest.fn();
const reduxAction = jest.fn().mockReturnValue({});
jest.useFakeTimers();
describe('someFunctionName', () => {
it('should dispatch reduxAction', async () => {
someFunctionName('value', dispatchMock, reduxAction);
jest.runAllTimers();
expect(reduxAction).toHaveBeenCalled();
});
});
Test keeps failing and i'm not sure why. I initially thought it could be the debounce method needs a mock, but that doesn't seem to fix it.