I want to write a test for a react component using 'react-datetime' library. The component is using a lot of moment functions which I have to mock with jest one after another. I all the time get errors in the console while running test and keep adding it to jest.mock function. I run into a problem because I get an error like:
TypeError: locale.longDateFormat is not a function
So I add it to jest mock:
jest.mock('moment', () => () => ({
localeData: () => ({
longDateFormat: () => '2011–01–30T12:34:56+00:00',
}),
}));
Then I get an error
TypeError: date.localeData is not a function
which dissapears when added:
localeData: () => '2011–01–30T12:34:56+00:00',
I am not able to add both at the same time as object must not have same keys... How can I combine these two so both errors get fixed? Or maybe there is a way to mock all moment's functions (as in jest.mock I currently have like 20 of them...)