Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

98
Views
Failing tests because of the daylight saving time change

I have tests where Im using getByText function in react-testing-library. Im looking for element in DOM that has value "10-10-2020 12:00". But after daylight saving time change, all my tests have failed because due to the change, the display text has changed to "10-10-2020 13:00" (one hour forwards) and now Im not able to get those elements. I will have to update my tests, but they will obviously fail once again when the time is changed in winter.

It happens because e.g. new Date('2020-01-01T00:00:00.000Z') returns 01 01 2020 01:00:00 instead of 01 01 2020 00:00:00 because of the timezones.

Is there any workaround or fix to make my tests resistant to daylight saving time change and timezones?

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Setting the hardcoded date and time for jest should help:

jest.useFakeTimers('modern')

beforeEach(() => {
  const hardcodedDate = new Date('2022-03-20T12:00:00Z')
  jest.setSystemTime(hardcodedDate.getTime())
})

It means in your tests you will always have the same system time, which will help with daylight saving time change (or any time change)

UPD: to see the date in the tests before the daylight saving you should change the hardcoded day before it started (for example in the UK it's 27 March)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!