Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document better how to restore synthetic clock #2910

Closed
bahmutov opened this issue Jun 23, 2020 · 3 comments · Fixed by #2911
Closed

Document better how to restore synthetic clock #2910

bahmutov opened this issue Jun 23, 2020 · 3 comments · Fixed by #2911

Comments

@bahmutov
Copy link
Contributor

Really hard to find https://docs.cypress.io/api/commands/tick.html#Yields

  • clock page
  • stubs and clocks page
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')
})

People cannot find it: https://twitter.com/huchenme/status/1275225026531225600

Related cypress-io/cypress-example-kitchensink#429

@huchenme
Copy link

Thanks for this. Can I suggest to have a cy.restoreClock() or cy.clockRestore() with implementation of below?

cy.tick().then(clock => {
   clock.restore();
})

@bahmutov
Copy link
Contributor Author

Shorthand

cy.tick().invoke('restore')

But still a dedicated command would be superior

@huchenme
Copy link

For some reason the trick does not work for me, I have to call .invoke('restore') on last tick() to make it work: huchenme/hacker-tab-extension@13bef19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants