You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 5, 2023. It is now read-only.
My requirement is, I am passing "new Date" in my method and getting back date/time with timezone offset like below:
const deliveryDate = abc.getDeliveryDate(new Date());
deliveryDate = "2020-04-14T15:20:33.982-05:00"
I would like to fix or hard code new Date() so that I get same date and time(with offset) every time.
Hi,
I am trying to mock new Date() but it is not working for me. It is giving below error:
Type 'typeof Date' is not assignable to type 'DateConstructor'.
I tried with your below code:
const getCurrentDate = () => new Date();
let realDate;
Using below code in my test spec:
realDate = Date;
global.Date = class extends Date {
constructor(...args) {
if (args.length > 0) {
// eslint-disable-next-line constructor-super, no-constructor-return
return super(...args);
}
My requirement is, I am passing "new Date" in my method and getting back date/time with timezone offset like below:
const deliveryDate = abc.getDeliveryDate(new Date());
deliveryDate = "2020-04-14T15:20:33.982-05:00"
I would like to fix or hard code new Date() so that I get same date and time(with offset) every time.