Has anyone out there had any success in getting cy.tick() to work in cypress component tests. cy.clock() stops the time but tick will not move it forward in cypress component tests. If someone was able to get this working please give mean example .
And again this is in cypress component testing not e2n testing.
I've also added clock to a before() method.
You can find an example component LoadingIndicator
plus test here set-timeout-example.
I ran the code in a new CRA application, and the test loading-indicator.cy.jsx
passed.
One of the tests that uses cy.tick()
is
it('should render loading indicator (mocks clock)', () => {
cy.clock()
mount(
<LoadingIndicator isLoading={true}>
<div>ahoy!</div>
</LoadingIndicator>,
)
// force 2 seconds to pass instantly
// and component's setTimeout to fire
cy.tick(2010)
cy.contains('loading...',
{ timeout: 100 } // fail if loader not displayed quickly
).should('be.visible')
})
Maybe your app does not use one of the supported native timer functions?