cypress-io / cypress-example-kitchensink

This is an example app used to showcase Cypress.io testing.
https://example.cypress.io/
MIT License
1.22k stars 2.2k forks source link

Show example how to restore synthetic clock #429

Open bahmutov opened 4 years ago

bahmutov commented 4 years ago
it('restores', () => {
  cy.clock(+ new Date())
  cy.visit('http://localhost:3000/sudoku')
  // make sure the application has rendered
  // and the synthetic clock started working
  cy.get('.game__cell--filled').should('have.length', 45)

  cy.tick(600 * 1000) // 10 minutes
  cy.contains('.status__time', '10:00')

  // resume the clock
  cy.tick().then(clock => {
    clock.restore()
  })
  // the clock is restored to original value
  // thus the timer will start measuring again
  // from the original date passed to "cy.clock"
  cy.contains('.status__time', '00:03')
})
bahmutov commented 4 years ago

People have trouble finding this info https://twitter.com/huchenme/status/1275225026531225600