tick
Move time after overriding a native time function with
cy.clock().
cy.clock() must be called before cy.tick() in order
to override native time functions first.
Syntax​
cy.tick(milliseconds, options)
Usage​
Correct Usage
cy.tick(500)
Arguments​
milliseconds (Number)
The number of milliseconds to move the clock. Any timers within the affected
range of time will be called.
options (Object)
Pass in an options object to change the default behavior of cy.tick().
| Option | Default | Description |
|---|---|---|
log | true | Displays the command in the Command log |
Yields ​
cy.tick() yields a clock object with the following methods:
-
clock.tick(milliseconds)Move the clock a number of milliseconds. Any timers within the affected range of time will be called.
-
clock.restore()Restore all overridden native functions. This is automatically called between tests, so should not generally be needed.
You can also access the clock object via this.clock in a
.then() callback.
Examples​
Milliseconds​
Create a clock and move time to trigger a setTimeout​
// app code loaded by index.html
window.addIntro = () => {
setTimeout(() => {
document.getElementById('#header').textContent = 'Hello, World'
}, 500)
}
cy.clock()
cy.visit('/index.html')
cy.window().invoke('addIntro')
cy.tick(500)
cy.get('#header').should('have.text', 'Hello, World')