mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-19 06:38:45 -05:00
2.2 KiB
2.2 KiB
title, comments, description
| title | comments | description |
|---|---|---|
| tick | true |
cy.tick is used to move time after overriding native time functions with cy.clock.
It moves the clock the specified number of milliseconds. Any timers within the affected range of time will be called.
cy.clock must be called before cy.tick in order to override native time functions first.
| Returns | the clock object. See clock API |
cy.tick( milliseconds )
Moves the clock the specified number of milliseconds. Any timers within the affected range of time will be called.
Usage
Create a clock and move time to trigger a setTimeout
// app code loaded by index.html
window.foo = () => {
setTimeout(() => {
document.getElementById('#foo').textContent = 'Foo'
}, 500)
}
// test
cy
.clock()
.visit("/index.html")
.window().invoke("foo")
.tick(500)
.get("#foo")
.should("have.text", "Foo")
Example Recipe
{% note info Using cy.clock and cy.tick %} Check out our example recipe testing spying, stubbing and time {% endnote %}
Command Log
Create a clock and tick it 1 second
cy
.clock()
.tick(1000)
The command above will display in the command log as:
When clicking on the tick command within the command log, the console outputs the following: