Mocking moment() and moment().format using jest

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)