Skip to content

Commit

Permalink
properly mock lodash in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Mar 31, 2020
1 parent 76818da commit 857c684
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ jest.doMock('@elastic/filesaver', () => ({
saveAs: saveAsMock,
}));

jest.doMock('lodash', () => ({
...jest.requireActual('lodash'),
debounce: (func: Function) => {
function debounced(this: any, ...args: any[]) {
return func.apply(this, args);
}
return debounced;
},
}));

export const findObjectsMock = jest.fn();
jest.doMock('../../lib/find_objects', () => ({
findObjects: findObjectsMock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ describe('SavedObjectsTable', () => {
};

beforeEach(() => {
extractExportDetailsMock.mockReset();

http = httpServiceMock.createStartContract();
overlays = overlayServiceMock.createStartContract();
notifications = notificationServiceMock.createStartContract();
Expand Down Expand Up @@ -200,18 +202,6 @@ describe('SavedObjectsTable', () => {
}));
});

beforeEach(() => {
extractExportDetailsMock.mockReset();
// mock _.debounce to fire immediately with no internal timer
require('lodash').debounce = (func: Function) => {
function debounced(...args: any[]) {
// @ts-ignore
return func.apply(this, args);
}
return debounced;
};
});

it('should render normally', async () => {
const component = shallowRender({ perPageConfig: 15 });

Expand Down

0 comments on commit 857c684

Please sign in to comment.