Wednesday, 30 September 2020

NodeJS testing datetimes with different times of the day and timezone

I have a situation that places today date in DB and I use vanilla code.

const todayCloseDate = new Date().toISOString().slice(0, 10);

This obviously introduces a problem with my timezone (CST) that after 5:00 PM date becomes the next day value. I changed handling to the package data-fns (moments.js is not an option).

const todayCloseDate = DF.format(new Date(), 'yyyy-MM-dd');

It works as expected. My question is how to unit test such change? It would require to make a change in system time of a local machine what locally run tests as well in any testing environment that would run tests in CI/CD pipeline (it would CircleCI, and Jenkins).

Would to start test scenario that would cover such bug and ensure fix? My test runner is Jest.



from NodeJS testing datetimes with different times of the day and timezone

No comments:

Post a Comment