#javascript #jest #node #Testing #dateMocking/stubbing the current Date in Jest testsThere are situations where new Date() or Date.now is used in application code. That code needs to be tested, and it’s always a struggle to remember how to mock/stub or spy on Date.now/new Date with Jest. This post goes through multiple approaches to mocking, stubbing and spying o ...
#javascript #dateAdd days to a Date in vanilla JavaScriptDespite the JavaScript Date warts, it’s straightforward to add day(s) to a date in JavaScript. While it would be very easy to reach for moment.js or another date manipulation library (date-fns, luxon, dayjs) to do something as simple as adding days to a Date in JavaScript, ...