Created
February 21, 2018 13:15
-
-
Save apieceofbart/d28690d52c46848c39d904ce8968bb27 to your computer and use it in GitHub Desktop.
mock lodash debounce in jest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// somewhere on top | |
import _ from 'lodash'; | |
jest.unmock('lodash'); | |
// then | |
_.debounce = jest.fn((fn) => fn); |
Updated version of @mos-adebayo's above that worked for me (using lodash-es
)
jest.mock('lodash-es', () => ({
...jest.requireActual('lodash-es'),
debounce: (fn) => {
fn.cancel = jest.fn();
return fn;
},
}));
You have to call the function and ignore the timer
jest.mock('lodash/fp/debounce', () =>jest.fn((nr, fn) => fn()))
. This worked for me.
👍
This worked for me perfectly:
import * as lodash from 'lodash-es';
// other imports...
jest.mock('lodash-es/debounce', () => ({
default: jest.fn(fn => fn),
__esModule: true
}));
// describe block...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks.