0

We updated to the latest Mui Date picker. And now we have a strange Problem with a failing snapshot test in our CI pipeline.

In our Jest Test, we set a fixed Date like this:

jest.useFakeTimers().setSystemTime(new Date('04 Dec 1995 00:12:00 GMT').getTime());

This test succeeds local, but when run int the CI pipeline it fails, because the data-timestamp value is different:

<button
                          aria-colindex="6"
                          aria-selected="false"
                          class="MuiButtonBase-root MuiPickersDay-root MuiPickersDay-dayWithMargin css-qa7bje-MuiButtonBase-root-MuiPickersDay-root"
                          data-timestamp="817772400000"
                          role="gridcell"
                          tabindex="-1"
                          type="button"
                        >

In the snapshot, you can see the correct date is used, to display the date picker. Only the timestamp value is not the expected one. Do I miss something here?

1 Answers1

0

I found the Solution, only setting a fixed time is not enough because the day boarders depend on the timezone. So I have to set the fixed date AND set a fixed timezone (in packages.json) to make it work.

In the Test:

jest.useFakeTimers().setSystemTime(new Date('04 Dec 1995 00:12:00 GMT').getTime());

And in packages.json:

"test": "set TZ=America/New_York && react-scripts test",