Date mock with two or more tests
问题 We are using jest for mocking. I have a function which will greet us based on the time that file looks like below: export default function getGreetingMessage() { const today = new Date(); const curHr = today.getHours(); if (curHr < 12) { return 'Good morning'; } else if (curHr < 18) { return 'Good afternoon'; } return 'Good evening'; } And My test file will look like below import getGreetingMessage from '../messages'; describe('messages', () => { function setup(date) { const DATE_TO_USE = new