So I trying to Mock a date in my test, this is what I did :
const mockDate = new Date('2018-01-01');
const backupDate = Date;
beforeEach(() => {
(global.Date as any) = jest.fn(() => mockDate);
})
afterEach(() => {
(global.Date as any) = backupDate;
jest.clearAllMocks();
});
const backupDate = Date;
(global.Date as any) = jest.fn(() => mockDate);
expect(myModule).toMatchSnapshot();
(global.Date as any) = jest.fn(() => backupDate);
So this test in my local works fine and it's match with my snapshots :
exports[`should match with date`] = `
[MockFunction] {
"calls": Array [
Array [
Object {
"myDate" : "Mon Jan 01 2018 01:00:00 GMT+0100 (Central European Standard Time)"
}]]}
but in production environment I getting this instead which cause failing the test : Mon Jan 01 2018 01:00:00 GMT+0100 (CET)
Any idea what is wrong?
I have a string composed by several fields. Two of which will always vary in length. I could simply use substring if all fields have fixed lengths. Sample: ...
I have a string composed by several fields. Two of which will always vary in length. I could simply use substring if all fields have fixed lengths. Sample: ...
I've figured out how to create an object based on an array, now I'm trying to understand how to build an array back from that object. with the object { social: { children: { ...
I've figured out how to create an object based on an array, now I'm trying to understand how to build an array back from that object. with the object { social: { children: { ...
Suppose I have this string: let string = '<h1 style="lots of class"> </h1><h2> <p style="bunch of class"> </p> <p style="bunch of class"> </p></h2>'; ...
Suppose I have this string: let string = '<h1 style="lots of class"> </h1><h2> <p style="bunch of class"> </p> <p style="bunch of class"> </p></h2>'; ...
i need to check whether the date is between minDate and maxDate. but when i try to compare with minDate, i should get valid as false but am getting true.. let minDate = "27-05-2019"; ...
i need to check whether the date is between minDate and maxDate. but when i try to compare with minDate, i should get valid as false but am getting true.. let minDate = "27-05-2019"; ...