cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.1k stars 3.19k forks source link

cy.tick does not advance the clock correctly #9674

Open bahmutov opened 4 years ago

bahmutov commented 4 years ago

Seems to only advance it by 1 second ...

  it.skip('shows the timer after 700 seconds (using cy.tick)', () => {
    const now = Cypress.moment('2010-01-20')
    cy.clock(now.toDate())
    mount(
      <SudokuContext.Provider value={{ timeGameStarted: now }}>
        <div className="innercontainer">
          <section className="status">
            <Timer />
          </section>
        </div>
      </SudokuContext.Provider>,
    )
    cy.contains('.status__time', '00:00')
    cy.tick(700 * 1000)
    cy.contains('.status__time', '11:40')
  })

in https://github.com/bahmutov/sudoku-qafest/blob/main/src/components/Timer.spec.js#L57

dmtrKovalenko commented 4 years ago

It looks like the spec is also affected by incorrect cy.tick https://github.com/bahmutov/cypress-react-unit-test/blob/bb3228172dedd425b292ce7ccf5b2d5817d8e297/cypress/component/advanced/framer-motion/Motion.spec.tsx#L13

cellog commented 2 years ago

this is still an issue, and is not just that it doesn't advance, cy.clock() + cy.tick() don't work at all in react component testing.

alexandrzavalii commented 1 year ago

is anyone looking at this issue?

glomotion commented 1 year ago

bump. on this issue. Im also seeing this right now.

wengzilla commented 1 year ago

I'm also noticing that something isn't working quite right for cy.clock() and component tests... For some reason not rendering my component properly. When I remove the cy.clock() it seems to work fine.

cypress-app-bot commented 1 year ago

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

mpavel commented 1 year ago

We also had issues with cy.clock() and Cypress 16.8.1 in a large React app. I've explained in https://github.com/cypress-io/cypress/issues/27744 how we overcame this. It would be interesting to see if you experience the same behaviour: will the UI assertions work if you restore the clock, before making the actual assertion?