I\'m unable to mock moment()
or moment().format
functions. I have states where, currentDateMoment
and currentDateFormatted
ar
The easiest way to mock moment() and any function that it uses (i.e. .day()
, .format()
) is to change the Date
that moment()
uses under the hood
Add the snippet below inside your test file
Date.now = jest.fn(() => new Date("2020-05-13T12:33:37.000Z"));
This makes it so anytime moment()
is called in your tests, moment()
thinks that today is Wednesday, May 13th 2020