How to mock lodash throttle in Jest

Spencer Feng
Aug 14, 2021

lodash throttle function creates a throttled function that only invokes the function that is passed in at most once every certain period of time. This lodash function is very useful in places where you want to throttle the invocation of some resource-intensive events, such as making API calls to a backend server when typing some texts in a text field.

However sometimes during unit tests, we want to mock lodash function. It actually is very easy to do it in Jest.

--

--