javascriptnode.jscypresscypress-cucumber-preprocessorcypress-component-test-runner

How to set current time to future time by using Cypress?


I am using cypress to automate countdown content block, I need to test recurrence scenarios by using Cypress. In Example,

At the Start - Days - 00 | Hrs - 00 | Mins - 00

I need to validate, after one hour, count down will be started (Days - 23 | Hrs - 59 | Mins - 59)

I cannot use hard-coded wait times, so I try the following cypress script but It won't work.

const now = new Date().getTime()
cy.clock(now)
cy.tick(3600000)

Anything worng in this? Or help me to find a good solution.


Solution

  • You can just create the currentNow you want and then set it

        const now = new Date(2011, 0, 11) // month is 0-indexed
        cy.clock(now)