telemo
telemo

Reputation: 21

Jest snapshot testing fail in GitLab pipeline due to timezone mismatch

I have normal Jest snapshot tests for a component that calls toDateString() and toTimeString().

The tests all pass when I run locally because both the tests and my component run in my current time zone (EST); however, when I check the tests into GitLab, the snapshot runs in EST, but the component calls the methods in Coordinated Universal Time, causing it to fail.

Is there a way to mock timezones in Jest? Or is there any other solution?

I am on Windows (not my choice).

Upvotes: 2

Views: 875

Answers (1)

lucas
lucas

Reputation: 1145

I managed to fix this issue adding TZ=UTC to my .env file. I'm using Mac though.

Upvotes: 1

Related Questions