Angular Unit Test - how simulate system clock timezone

2.3k views Asked by At

How is it possible to simulate the system clock being set to another timezone in an Angular Unit Test with Karma/Jasmine.

I am working an a custom datetime picker component. It has a bug that can only be reproduced when using it in a different timezone. To write a proper unit test for the fix I want to simulate the exact same situation.

I can reproduce the bug by switching the system clock manually in the windows settings:

E.g. enter image description here

Now I want to move the system time switch to the unit test to simulate the behavior of the component in different timezones.

I tried to use jasmine.clock like this: jasmine.clock().mockDate(moment.tz("2020-10-09 10:00:00", "Asia/Bangkok").toDate());

But it does not really change the timezone like changing the system clock does. Jasmine clock changes indeed the time, but it stays in the timezone of the system (which is Central European Time).

0

There are 0 answers