最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to handle timezones in Cypress snapshot tests? - Stack Overflow

programmeradmin0浏览0评论

We use Cypress and cypress-image-snapshot for snapshot testing. Unfortunately we have issues with our colleagues based in another countries running the tests since they fail because of different timezones. In our date related components we pass strings in ISO 8601 format to set the date.

For our jest tests we use mocks (Components using Date objects produce different snapshots in different timezones) but not quite sure how to handle the situation in Cypress.

We use Cypress and cypress-image-snapshot for snapshot testing. Unfortunately we have issues with our colleagues based in another countries running the tests since they fail because of different timezones. In our date related components we pass strings in ISO 8601 format to set the date.

For our jest tests we use mocks (Components using Date objects produce different snapshots in different timezones) but not quite sure how to handle the situation in Cypress.

Share Improve this question edited Nov 10, 2019 at 17:01 jonrsharpe 122k30 gold badges266 silver badges473 bronze badges asked Nov 10, 2019 at 16:45 pollxpollx 6999 silver badges23 bronze badges 3
  • The Cypress docs specifically highlight cy.clock, have you looked into that? – jonrsharpe Commented Nov 10, 2019 at 16:47
  • 3 cy.clock() is for speeding up JS timer functions like setTimeout(), nothing to do with timezones so you can ignore that approach. – Ackroydd Commented Nov 13, 2019 at 19:37
  • 1 You should be able to manage timezone issues by structuring the test so that it only checks relative time values. Could you please post a simple example to illustrate the problem? – Ackroydd Commented Nov 13, 2019 at 19:38
Add a comment  | 

1 Answer 1

Reset to default 18

You can open browser with different TZ from server by adding specific timezone before open, in this way

"scripts": {
  "cypress:open": "TZ=America/New_York cypress open",
  "cypress:run": "TZ=America/New_York cypress run"
}
发布评论

评论列表(0)

  1. 暂无评论