{
  "doc": {
    "id": "api/commands/clock",
    "title": "cy.clock()",
    "description": "Override native global functions related to time allowing them to be controlled synchronously via cy.tick() or the yielded clock object.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/clock.md",
    "version": "f97f06d85653c51afe39a9bd3cefda946807f150",
    "updated_at": "2026-10-05T21:01:45.863Z",
    "headings": [
      {
        "id": "api/commands/clock#clock",
        "text": "clock",
        "level": 1
      },
      {
        "id": "api/commands/clock#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/clock#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/clock#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/clock#yields",
        "text": "Yields",
        "level": 3
      },
      {
        "id": "api/commands/clock#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/clock#no-args",
        "text": "No Args",
        "level": 3
      },
      {
        "id": "api/commands/clock#create-a-clock-and-use-it-to-trigger-a-setinterval",
        "text": "Create a clock and use it to trigger a setInterval",
        "level": 4
      },
      {
        "id": "api/commands/clock#test-a-debounced-search-input-with-cy-clock",
        "text": "Test a debounced search input with cy.clock()",
        "level": 4
      },
      {
        "id": "api/commands/clock#test-an-inactivity-timeout-with-cy-clock",
        "text": "Test an inactivity timeout with cy.clock()",
        "level": 4
      },
      {
        "id": "api/commands/clock#access-the-clock-object-to-synchronously-move-time",
        "text": "Access the clock object to synchronously move time",
        "level": 4
      },
      {
        "id": "api/commands/clock#access-the-clock-object-to-restore-native-functions",
        "text": "Access the clock object to restore native functions",
        "level": 4
      },
      {
        "id": "api/commands/clock#now",
        "text": "Now",
        "level": 3
      },
      {
        "id": "api/commands/clock#specify-a-now-timestamp",
        "text": "Specify a now timestamp",
        "level": 4
      },
      {
        "id": "api/commands/clock#start-every-test-on-the-same-date-with-cy-clock",
        "text": "Start every test on the same date with cy.clock()",
        "level": 4
      },
      {
        "id": "api/commands/clock#test-a-midnight-date-rollover-with-cy-clock",
        "text": "Test a midnight date rollover with cy.clock()",
        "level": 4
      },
      {
        "id": "api/commands/clock#function-names",
        "text": "Function names",
        "level": 3
      },
      {
        "id": "api/commands/clock#specify-which-functions-to-override",
        "text": "Specify which functions to override",
        "level": 4
      },
      {
        "id": "api/commands/clock#freeze-the-date-and-keep-animations-running-with-cy-clock",
        "text": "Freeze the date and keep animations running with cy.clock()",
        "level": 4
      },
      {
        "id": "api/commands/clock#using-cy-clock-with-cy-tick",
        "text": "Using cy.clock() with cy.tick()",
        "level": 4
      },
      {
        "id": "api/commands/clock#restore-clock",
        "text": "Restore clock",
        "level": 3
      },
      {
        "id": "api/commands/clock#change-current-system-time",
        "text": "Change current system time",
        "level": 3
      },
      {
        "id": "api/commands/clock#notes",
        "text": "Notes",
        "level": 2
      },
      {
        "id": "api/commands/clock#iframes",
        "text": "iframes",
        "level": 3
      },
      {
        "id": "api/commands/clock#iframes-not-supported",
        "text": "iframes not supported",
        "level": 4
      },
      {
        "id": "api/commands/clock#behavior",
        "text": "Behavior",
        "level": 3
      },
      {
        "id": "api/commands/clock#css-animations-and-transitions-ignore-cy-clock",
        "text": "CSS animations and transitions ignore cy.clock()",
        "level": 4
      },
      {
        "id": "api/commands/clock#clock-behavior-before-cy-mount",
        "text": "clock behavior before cy.mount()",
        "level": 4
      },
      {
        "id": "api/commands/clock#clock-behavior-before-cy-visit",
        "text": "clock behavior before cy.visit()",
        "level": 4
      },
      {
        "id": "api/commands/clock#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/clock#requirements",
        "text": "Requirements",
        "level": 3
      },
      {
        "id": "api/commands/clock#assertions",
        "text": "Assertions",
        "level": 3
      },
      {
        "id": "api/commands/clock#timeouts",
        "text": "Timeouts",
        "level": 3
      },
      {
        "id": "api/commands/clock#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/clock#history",
        "text": "History",
        "level": 2
      },
      {
        "id": "api/commands/clock#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/commands/clock#syntax",
      "doc_id": "api/commands/clock",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\ncy.clock()\ncy.clock(now)\ncy.clock(now, functionNames)\ncy.clock(options)\ncy.clock(now, options)\ncy.clock(now, functionNames, options)\n```\n\n### Usage\n\n**Correct Usage**\n\n```\ncy.clock()\n```\n\n### Arguments\n\n**now _(number, Date)_**\n\nA timestamp or `Date` object specifying where the clock should start. Pass `0` (or `null`) to start at the unix epoch while still passing `functionNames`.\n\n**functionNames _(Array)_**\n\nNames of the native functions the clock should override. When omitted, or when passed an empty array, `cy.clock()` overrides the default set listed above. Valid names are `setTimeout`, `clearTimeout`, `setInterval`, `clearInterval`, `Date`, `requestAnimationFrame`, `cancelAnimationFrame`, `requestIdleCallback`, `cancelIdleCallback`, `performance`, and `Intl`.\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `cy.clock()`.\n\n| Option | Default | Description |\n| --- | --- | --- |\n| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |\n\n### Yields\n\n`cy.clock()` yields a `clock` object with the following methods. If a clock already exists in the current test, `cy.clock()` yields that existing clock and ignores any arguments passed to it.\n\n*   **`clock.tick(milliseconds)`**\n    \n    Move the clock the specified number of `milliseconds`. Any timers within the affected range of time are called.\n    \n*   **`clock.restore()`**\n    \n    Restore all overridden native functions. This is automatically called between tests, so should not generally be needed.\n    \n    `clock.restore()` returns native timer APIs (`setTimeout`, `setInterval`, etc.) to the `window`. New timers created _after_ `restore()` run in real time. Timers registered while the fake clock was active are discarded and don't resume automatically.\n    \n*   **`clock.setSystemTime(now)`**\n    \n    Change the system time to the new `now`. Now can be a timestamp, date object, or not passed in which defaults to 0. It doesn't call any timers or change the time left before they trigger.\n    \n\nYou can also access the `clock` object via `this.clock` in a [`.then()`](/llm/markdown/api/commands/then.md) callback, as long as the test is written with a `function () {}` callback rather than an arrow function, so `this` refers to the test context.\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 419
    },
    {
      "id": "api/commands/clock#arguments",
      "doc_id": "api/commands/clock",
      "heading": "Arguments",
      "heading_level": 3,
      "content_markdown": "### Arguments\n\n**now _(number, Date)_**\n\nA timestamp or `Date` object specifying where the clock should start. Pass `0` (or `null`) to start at the unix epoch while still passing `functionNames`.\n\n**functionNames _(Array)_**\n\nNames of the native functions the clock should override. When omitted, or when passed an empty array, `cy.clock()` overrides the default set listed above. Valid names are `setTimeout`, `clearTimeout`, `setInterval`, `clearInterval`, `Date`, `requestAnimationFrame`, `cancelAnimationFrame`, `requestIdleCallback`, `cancelIdleCallback`, `performance`, and `Intl`.\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `cy.clock()`.\n\n| Option | Default | Description |\n| --- | --- | --- |\n| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |\n",
      "section": "api",
      "anchors": [
        "arguments"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 149
    },
    {
      "id": "api/commands/clock#yields",
      "doc_id": "api/commands/clock",
      "heading": "Yields",
      "heading_level": 3,
      "content_markdown": "### Yields\n\n`cy.clock()` yields a `clock` object with the following methods. If a clock already exists in the current test, `cy.clock()` yields that existing clock and ignores any arguments passed to it.\n\n*   **`clock.tick(milliseconds)`**\n    \n    Move the clock the specified number of `milliseconds`. Any timers within the affected range of time are called.\n    \n*   **`clock.restore()`**\n    \n    Restore all overridden native functions. This is automatically called between tests, so should not generally be needed.\n    \n    `clock.restore()` returns native timer APIs (`setTimeout`, `setInterval`, etc.) to the `window`. New timers created _after_ `restore()` run in real time. Timers registered while the fake clock was active are discarded and don't resume automatically.\n    \n*   **`clock.setSystemTime(now)`**\n    \n    Change the system time to the new `now`. Now can be a timestamp, date object, or not passed in which defaults to 0. It doesn't call any timers or change the time left before they trigger.\n    \n\nYou can also access the `clock` object via `this.clock` in a [`.then()`](/llm/markdown/api/commands/then.md) callback, as long as the test is written with a `function () {}` callback rather than an arrow function, so `this` refers to the test context.\n",
      "section": "api",
      "anchors": [
        "yields"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 241
    },
    {
      "id": "api/commands/clock#examples",
      "doc_id": "api/commands/clock",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\n### No Args\n\n#### Create a clock and use it to trigger a `setInterval`\n\nsrc/timer.js\n\n```\nlet seconds = 0\n\nsetInterval(() => {\n  $('#seconds-elapsed').text(++seconds + ' seconds')\n}, 1000)\n```\n\ncypress/e2e/timer.cy.js\n\n```\ncy.clock()\ncy.visit('/index.html')\ncy.tick(1000)\ncy.get('#seconds-elapsed').should('have.text', '1 seconds')\ncy.tick(1000)\ncy.get('#seconds-elapsed').should('have.text', '2 seconds')\n```\n\n#### Test a debounced search input with `cy.clock()`\n\nA debounced input waits for the user to stop typing before it acts. With `cy.clock()`, you control exactly when that wait ends, so you can assert both that nothing happens too early and that the request fires on time.\n\nsrc/search.js\n\n```\nlet debounceTimer\n\n$('#search').on('input', (e) => {\n  clearTimeout(debounceTimer)\n  debounceTimer = setTimeout(() => {\n    fetch(`/api/search?q=${e.target.value}`)\n  }, 300)\n})\n```\n\ncypress/e2e/search.cy.js\n\n```\ncy.intercept('GET', '/api/search*').as('search')\ncy.clock()\ncy.visit('/products')\ncy.get('#search').type('shoes')\n// the debounce hasn't elapsed, so no request has been sent\ncy.get('@search.all').should('have.length', 0)\ncy.tick(300)\ncy.wait('@search')\n```\n\n#### Test an inactivity timeout with `cy.clock()`\n\nSession expiry warnings and automatic logouts often wait many minutes before they trigger. Move the clock forward instead of waiting in real time.\n\n```\ncy.clock()\ncy.visit('/dashboard')\ncy.tick(15 * 60 * 1000) // 15 minutes\ncy.contains('Your session has expired').should('be.visible')\n```\n\n#### Access the clock object to synchronously move time\n\nIn most cases, it's easier to use [`cy.tick()`](/llm/markdown/api/commands/tick.md) to move time, but you can also use the `clock` object yielded by `cy.clock()`.\n\n```\ncy.clock().then((clock) => {\n  clock.tick(1000)\n})\n```\n\nYou can call `cy.clock()` again for this purpose later in a chain if necessary. It yields the clock that already exists and ignores any arguments, so it can't change `now` or `functionNames`. Use `clock.setSystemTime()` to change the current time.\n\n```\ncy.clock()\ncy.get('input').type('Jane Lane')\ncy.clock().then((clock) => {\n  clock.tick(1000)\n})\n```\n\nThe clock object is also available via `this.clock` in any [`.then()`](/llm/markdown/api/commands/then.md) callback. Use a `function () {}` test callback so `this` refers to the test context.\n\n```\nit('ticks the clock', function () {\n  cy.clock()\n  cy.get('form').then(($form) => {\n    this.clock.tick(1000)\n    // do something with $form ...\n  })\n})\n```\n\n#### Access the clock object to restore native functions\n\nIn general, it should not be necessary to manually restore the native functions that `cy.clock()` overrides since this is done automatically between tests. But if you need to, the `clock` object yield has a `.restore()` method.\n\n```\ncy.clock().then((clock) => {\n  clock.restore()\n})\n```\n\nOr via `this.clock`:\n\n```\nit('restores the clock', function () {\n  cy.clock()\n  cy.get('.timer').then(($timer) => {\n    this.clock.restore()\n    // do something with $timer ...\n  })\n})\n```\n\n### Now\n\n#### Specify a now timestamp\n\n*   End-to-End Test\n*   Component Test\n\n```\nconst now = new Date(2021, 3, 14) // month is 0-indexed\n\ncy.clock(now)\ncy.visit('/index.html')\ncy.get('#date').should('have.value', '04/14/2021')\n```\n\n```\nconst now = new Date(2021, 3, 14) // month is 0-indexed\n\ncy.clock(now)\ncy.mount(<DatePicker id=\"date\" />)\ncy.get('#date').should('have.value', '04/14/2021')\n```\n\n#### Start every test on the same date with `cy.clock()`\n\nCall `cy.clock()` in a `beforeEach()` hook so every test sees the same current date. Cypress restores the clock automatically after each test, so each test starts with a fresh clock set to the same `now`.\n\n```\nbeforeEach(() => {\n  cy.clock(Date.UTC(2026, 0, 15))\n  cy.visit('/reports')\n})\n```\n\n#### Test a midnight date rollover with `cy.clock()`\n\nCombine a `now` value with [`cy.tick()`](/llm/markdown/api/commands/tick.md) to test what happens when time crosses a boundary, such as midnight. This example assumes the app updates its displayed date on a timer.\n\n```\ncy.clock(new Date(2026, 0, 31, 23, 59, 59)) // one second before midnight\ncy.visit('/calendar')\ncy.get('#today').should('contain', 'January 31')\ncy.tick(1000)\ncy.get('#today').should('contain', 'February 1')\n```\n\n### Function names\n\n#### Specify which functions to override\n\nThis example overrides only `setTimeout` and `clearTimeout` and leaves the other time-related functions as they are.\n\n```\ncy.clock(null, ['setTimeout', 'clearTimeout'])\n```\n\nYou must specify `Date` to override the current datetime. The example below affects the current datetime without affecting scheduled timers.\n\n```\ncy.clock(Date.UTC(2018, 10, 30), ['Date'])\n```\n\n#### Freeze the date and keep animations running with `cy.clock()`\n\nBy default, `cy.clock()` also overrides `requestAnimationFrame`, so JavaScript animations and any rendering that relies on animation frames only advance when you call [`cy.tick()`](/llm/markdown/api/commands/tick.md). To freeze the date and control timeouts while leaving animation frames running in real time, list only the functions you want to override.\n\n```\ncy.clock(Date.UTC(2026, 0, 1), ['Date', 'setTimeout', 'clearTimeout'])\n```\n\n#### `Using cy.clock()` with `cy.tick()`\n\n[Check out our example recipe testing spying, stubbing, and time.](/llm/markdown/app/references/recipes.md#Stubbing-and-spying)\n\n### Restore clock\n\nYou can restore the clock and allow your application to resume normally without manipulating native global functions related to time. This is automatically called between tests.\n\n`clock.restore()` returns native timer APIs (`setTimeout`, `setInterval`, etc.) to the `window`. New timers created _after_ `restore()` run in real time. Timers registered while the fake clock was active are discarded and don't resume automatically. If your application code needs to keep running after `restore()`, it must re-register those timers itself. Timers your application registered before `cy.clock()` was called were never faked, so they keep running in real time.\n\n```\ncy.clock()\ncy.visit('http://localhost:3333')\ncy.get('#search').type('Acme Company')\ncy.tick(1000)\n// more test code here\n\n// restore the clock\ncy.clock().then((clock) => {\n  clock.restore()\n})\n// more test code here\n```\n\nYou could also restore by using [.invoke()](/llm/markdown/api/commands/invoke.md) to invoke the `restore` function.\n\n```\ncy.clock().invoke('restore')\n```\n\n### Change current system time\n\nThis example tests that a timer still displays correctly after it has run for an hour, without triggering an hour's worth of `setInterval` or `requestAnimationFrame` callbacks and overloading your CPU.\n\n```\ncy.clock(0)\ncy.visit('http://localhost:3333')\ncy.clock().then((clock) => {\n  clock.setSystemTime(60 * 60 * 1000 - 60)\n  // setSystemTime doesn't trigger any timers, so we run the last frame\n  // with tick to trigger a callback to update the timer.\n  clock.tick(60)\n})\n// the timer shows an hour has passed and still fits on the page\ncy.get('#timer').should('contain', '1:00:00').and('be.visible')\n// more test code here\n```\n\nYou could also change the system time by using [.invoke()](/llm/markdown/api/commands/invoke.md) to invoke the `setSystemTime` function.\n\n```\ncy.clock().invoke('setSystemTime', 60 * 60 * 1000)\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 1260
    },
    {
      "id": "api/commands/clock#no-args",
      "doc_id": "api/commands/clock",
      "heading": "No Args",
      "heading_level": 3,
      "content_markdown": "### No Args\n\n#### Create a clock and use it to trigger a `setInterval`\n\nsrc/timer.js\n\n```\nlet seconds = 0\n\nsetInterval(() => {\n  $('#seconds-elapsed').text(++seconds + ' seconds')\n}, 1000)\n```\n\ncypress/e2e/timer.cy.js\n\n```\ncy.clock()\ncy.visit('/index.html')\ncy.tick(1000)\ncy.get('#seconds-elapsed').should('have.text', '1 seconds')\ncy.tick(1000)\ncy.get('#seconds-elapsed').should('have.text', '2 seconds')\n```\n\n#### Test a debounced search input with `cy.clock()`\n\nA debounced input waits for the user to stop typing before it acts. With `cy.clock()`, you control exactly when that wait ends, so you can assert both that nothing happens too early and that the request fires on time.\n\nsrc/search.js\n\n```\nlet debounceTimer\n\n$('#search').on('input', (e) => {\n  clearTimeout(debounceTimer)\n  debounceTimer = setTimeout(() => {\n    fetch(`/api/search?q=${e.target.value}`)\n  }, 300)\n})\n```\n\ncypress/e2e/search.cy.js\n\n```\ncy.intercept('GET', '/api/search*').as('search')\ncy.clock()\ncy.visit('/products')\ncy.get('#search').type('shoes')\n// the debounce hasn't elapsed, so no request has been sent\ncy.get('@search.all').should('have.length', 0)\ncy.tick(300)\ncy.wait('@search')\n```\n\n#### Test an inactivity timeout with `cy.clock()`\n\nSession expiry warnings and automatic logouts often wait many minutes before they trigger. Move the clock forward instead of waiting in real time.\n\n```\ncy.clock()\ncy.visit('/dashboard')\ncy.tick(15 * 60 * 1000) // 15 minutes\ncy.contains('Your session has expired').should('be.visible')\n```\n\n#### Access the clock object to synchronously move time\n\nIn most cases, it's easier to use [`cy.tick()`](/llm/markdown/api/commands/tick.md) to move time, but you can also use the `clock` object yielded by `cy.clock()`.\n\n```\ncy.clock().then((clock) => {\n  clock.tick(1000)\n})\n```\n\nYou can call `cy.clock()` again for this purpose later in a chain if necessary. It yields the clock that already exists and ignores any arguments, so it can't change `now` or `functionNames`. Use `clock.setSystemTime()` to change the current time.\n\n```\ncy.clock()\ncy.get('input').type('Jane Lane')\ncy.clock().then((clock) => {\n  clock.tick(1000)\n})\n```\n\nThe clock object is also available via `this.clock` in any [`.then()`](/llm/markdown/api/commands/then.md) callback. Use a `function () {}` test callback so `this` refers to the test context.\n\n```\nit('ticks the clock', function () {\n  cy.clock()\n  cy.get('form').then(($form) => {\n    this.clock.tick(1000)\n    // do something with $form ...\n  })\n})\n```\n\n#### Access the clock object to restore native functions\n\nIn general, it should not be necessary to manually restore the native functions that `cy.clock()` overrides since this is done automatically between tests. But if you need to, the `clock` object yield has a `.restore()` method.\n\n```\ncy.clock().then((clock) => {\n  clock.restore()\n})\n```\n\nOr via `this.clock`:\n\n```\nit('restores the clock', function () {\n  cy.clock()\n  cy.get('.timer').then(($timer) => {\n    this.clock.restore()\n    // do something with $timer ...\n  })\n})\n```\n",
      "section": "api",
      "anchors": [
        "no-args"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 517
    },
    {
      "id": "api/commands/clock#create-a-clock-and-use-it-to-trigger-a-setinterval",
      "doc_id": "api/commands/clock",
      "heading": "Create a clock and use it to trigger a setInterval",
      "heading_level": 4,
      "content_markdown": "#### Create a clock and use it to trigger a `setInterval`\n\nsrc/timer.js\n\n```\nlet seconds = 0\n\nsetInterval(() => {\n  $('#seconds-elapsed').text(++seconds + ' seconds')\n}, 1000)\n```\n\ncypress/e2e/timer.cy.js\n\n```\ncy.clock()\ncy.visit('/index.html')\ncy.tick(1000)\ncy.get('#seconds-elapsed').should('have.text', '1 seconds')\ncy.tick(1000)\ncy.get('#seconds-elapsed').should('have.text', '2 seconds')\n```\n",
      "section": "api",
      "anchors": [
        "create-a-clock-and-use-it-to-trigger-a-setinterval"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 53
    },
    {
      "id": "api/commands/clock#test-a-debounced-search-input-with-cy-clock",
      "doc_id": "api/commands/clock",
      "heading": "Test a debounced search input with cy.clock()",
      "heading_level": 4,
      "content_markdown": "#### Test a debounced search input with `cy.clock()`\n\nA debounced input waits for the user to stop typing before it acts. With `cy.clock()`, you control exactly when that wait ends, so you can assert both that nothing happens too early and that the request fires on time.\n\nsrc/search.js\n\n```\nlet debounceTimer\n\n$('#search').on('input', (e) => {\n  clearTimeout(debounceTimer)\n  debounceTimer = setTimeout(() => {\n    fetch(`/api/search?q=${e.target.value}`)\n  }, 300)\n})\n```\n\ncypress/e2e/search.cy.js\n\n```\ncy.intercept('GET', '/api/search*').as('search')\ncy.clock()\ncy.visit('/products')\ncy.get('#search').type('shoes')\n// the debounce hasn't elapsed, so no request has been sent\ncy.get('@search.all').should('have.length', 0)\ncy.tick(300)\ncy.wait('@search')\n```\n",
      "section": "api",
      "anchors": [
        "test-a-debounced-search-input-with-cy-clock"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 119
    },
    {
      "id": "api/commands/clock#test-an-inactivity-timeout-with-cy-clock",
      "doc_id": "api/commands/clock",
      "heading": "Test an inactivity timeout with cy.clock()",
      "heading_level": 4,
      "content_markdown": "#### Test an inactivity timeout with `cy.clock()`\n\nSession expiry warnings and automatic logouts often wait many minutes before they trigger. Move the clock forward instead of waiting in real time.\n\n```\ncy.clock()\ncy.visit('/dashboard')\ncy.tick(15 * 60 * 1000) // 15 minutes\ncy.contains('Your session has expired').should('be.visible')\n```\n",
      "section": "api",
      "anchors": [
        "test-an-inactivity-timeout-with-cy-clock"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 61
    },
    {
      "id": "api/commands/clock#access-the-clock-object-to-synchronously-move-time",
      "doc_id": "api/commands/clock",
      "heading": "Access the clock object to synchronously move time",
      "heading_level": 4,
      "content_markdown": "#### Access the clock object to synchronously move time\n\nIn most cases, it's easier to use [`cy.tick()`](/llm/markdown/api/commands/tick.md) to move time, but you can also use the `clock` object yielded by `cy.clock()`.\n\n```\ncy.clock().then((clock) => {\n  clock.tick(1000)\n})\n```\n\nYou can call `cy.clock()` again for this purpose later in a chain if necessary. It yields the clock that already exists and ignores any arguments, so it can't change `now` or `functionNames`. Use `clock.setSystemTime()` to change the current time.\n\n```\ncy.clock()\ncy.get('input').type('Jane Lane')\ncy.clock().then((clock) => {\n  clock.tick(1000)\n})\n```\n\nThe clock object is also available via `this.clock` in any [`.then()`](/llm/markdown/api/commands/then.md) callback. Use a `function () {}` test callback so `this` refers to the test context.\n\n```\nit('ticks the clock', function () {\n  cy.clock()\n  cy.get('form').then(($form) => {\n    this.clock.tick(1000)\n    // do something with $form ...\n  })\n})\n```\n",
      "section": "api",
      "anchors": [
        "access-the-clock-object-to-synchronously-move-time"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 179
    },
    {
      "id": "api/commands/clock#access-the-clock-object-to-restore-native-functions",
      "doc_id": "api/commands/clock",
      "heading": "Access the clock object to restore native functions",
      "heading_level": 4,
      "content_markdown": "#### Access the clock object to restore native functions\n\nIn general, it should not be necessary to manually restore the native functions that `cy.clock()` overrides since this is done automatically between tests. But if you need to, the `clock` object yield has a `.restore()` method.\n\n```\ncy.clock().then((clock) => {\n  clock.restore()\n})\n```\n\nOr via `this.clock`:\n\n```\nit('restores the clock', function () {\n  cy.clock()\n  cy.get('.timer').then(($timer) => {\n    this.clock.restore()\n    // do something with $timer ...\n  })\n})\n```\n",
      "section": "api",
      "anchors": [
        "access-the-clock-object-to-restore-native-functions"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 101
    },
    {
      "id": "api/commands/clock#now",
      "doc_id": "api/commands/clock",
      "heading": "Now",
      "heading_level": 3,
      "content_markdown": "### Now\n\n#### Specify a now timestamp\n\n*   End-to-End Test\n*   Component Test\n\n```\nconst now = new Date(2021, 3, 14) // month is 0-indexed\n\ncy.clock(now)\ncy.visit('/index.html')\ncy.get('#date').should('have.value', '04/14/2021')\n```\n\n```\nconst now = new Date(2021, 3, 14) // month is 0-indexed\n\ncy.clock(now)\ncy.mount(<DatePicker id=\"date\" />)\ncy.get('#date').should('have.value', '04/14/2021')\n```\n\n#### Start every test on the same date with `cy.clock()`\n\nCall `cy.clock()` in a `beforeEach()` hook so every test sees the same current date. Cypress restores the clock automatically after each test, so each test starts with a fresh clock set to the same `now`.\n\n```\nbeforeEach(() => {\n  cy.clock(Date.UTC(2026, 0, 15))\n  cy.visit('/reports')\n})\n```\n\n#### Test a midnight date rollover with `cy.clock()`\n\nCombine a `now` value with [`cy.tick()`](/llm/markdown/api/commands/tick.md) to test what happens when time crosses a boundary, such as midnight. This example assumes the app updates its displayed date on a timer.\n\n```\ncy.clock(new Date(2026, 0, 31, 23, 59, 59)) // one second before midnight\ncy.visit('/calendar')\ncy.get('#today').should('contain', 'January 31')\ncy.tick(1000)\ncy.get('#today').should('contain', 'February 1')\n```\n",
      "section": "api",
      "anchors": [
        "now"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 219
    },
    {
      "id": "api/commands/clock#specify-a-now-timestamp",
      "doc_id": "api/commands/clock",
      "heading": "Specify a now timestamp",
      "heading_level": 4,
      "content_markdown": "#### Specify a now timestamp\n\n*   End-to-End Test\n*   Component Test\n\n```\nconst now = new Date(2021, 3, 14) // month is 0-indexed\n\ncy.clock(now)\ncy.visit('/index.html')\ncy.get('#date').should('have.value', '04/14/2021')\n```\n\n```\nconst now = new Date(2021, 3, 14) // month is 0-indexed\n\ncy.clock(now)\ncy.mount(<DatePicker id=\"date\" />)\ncy.get('#date').should('have.value', '04/14/2021')\n```\n",
      "section": "api",
      "anchors": [
        "specify-a-now-timestamp"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 63
    },
    {
      "id": "api/commands/clock#start-every-test-on-the-same-date-with-cy-clock",
      "doc_id": "api/commands/clock",
      "heading": "Start every test on the same date with cy.clock()",
      "heading_level": 4,
      "content_markdown": "#### Start every test on the same date with `cy.clock()`\n\nCall `cy.clock()` in a `beforeEach()` hook so every test sees the same current date. Cypress restores the clock automatically after each test, so each test starts with a fresh clock set to the same `now`.\n\n```\nbeforeEach(() => {\n  cy.clock(Date.UTC(2026, 0, 15))\n  cy.visit('/reports')\n})\n```\n",
      "section": "api",
      "anchors": [
        "start-every-test-on-the-same-date-with-cy-clock"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 73
    },
    {
      "id": "api/commands/clock#test-a-midnight-date-rollover-with-cy-clock",
      "doc_id": "api/commands/clock",
      "heading": "Test a midnight date rollover with cy.clock()",
      "heading_level": 4,
      "content_markdown": "#### Test a midnight date rollover with `cy.clock()`\n\nCombine a `now` value with [`cy.tick()`](/llm/markdown/api/commands/tick.md) to test what happens when time crosses a boundary, such as midnight. This example assumes the app updates its displayed date on a timer.\n\n```\ncy.clock(new Date(2026, 0, 31, 23, 59, 59)) // one second before midnight\ncy.visit('/calendar')\ncy.get('#today').should('contain', 'January 31')\ncy.tick(1000)\ncy.get('#today').should('contain', 'February 1')\n```\n",
      "section": "api",
      "anchors": [
        "test-a-midnight-date-rollover-with-cy-clock"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 80
    },
    {
      "id": "api/commands/clock#function-names",
      "doc_id": "api/commands/clock",
      "heading": "Function names",
      "heading_level": 3,
      "content_markdown": "### Function names\n\n#### Specify which functions to override\n\nThis example overrides only `setTimeout` and `clearTimeout` and leaves the other time-related functions as they are.\n\n```\ncy.clock(null, ['setTimeout', 'clearTimeout'])\n```\n\nYou must specify `Date` to override the current datetime. The example below affects the current datetime without affecting scheduled timers.\n\n```\ncy.clock(Date.UTC(2018, 10, 30), ['Date'])\n```\n\n#### Freeze the date and keep animations running with `cy.clock()`\n\nBy default, `cy.clock()` also overrides `requestAnimationFrame`, so JavaScript animations and any rendering that relies on animation frames only advance when you call [`cy.tick()`](/llm/markdown/api/commands/tick.md). To freeze the date and control timeouts while leaving animation frames running in real time, list only the functions you want to override.\n\n```\ncy.clock(Date.UTC(2026, 0, 1), ['Date', 'setTimeout', 'clearTimeout'])\n```\n\n#### `Using cy.clock()` with `cy.tick()`\n\n[Check out our example recipe testing spying, stubbing, and time.](/llm/markdown/app/references/recipes.md#Stubbing-and-spying)\n",
      "section": "api",
      "anchors": [
        "function-names"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 180
    },
    {
      "id": "api/commands/clock#specify-which-functions-to-override",
      "doc_id": "api/commands/clock",
      "heading": "Specify which functions to override",
      "heading_level": 4,
      "content_markdown": "#### Specify which functions to override\n\nThis example overrides only `setTimeout` and `clearTimeout` and leaves the other time-related functions as they are.\n\n```\ncy.clock(null, ['setTimeout', 'clearTimeout'])\n```\n\nYou must specify `Date` to override the current datetime. The example below affects the current datetime without affecting scheduled timers.\n\n```\ncy.clock(Date.UTC(2018, 10, 30), ['Date'])\n```\n",
      "section": "api",
      "anchors": [
        "specify-which-functions-to-override"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 71
    },
    {
      "id": "api/commands/clock#freeze-the-date-and-keep-animations-running-with-cy-clock",
      "doc_id": "api/commands/clock",
      "heading": "Freeze the date and keep animations running with cy.clock()",
      "heading_level": 4,
      "content_markdown": "#### Freeze the date and keep animations running with `cy.clock()`\n\nBy default, `cy.clock()` also overrides `requestAnimationFrame`, so JavaScript animations and any rendering that relies on animation frames only advance when you call [`cy.tick()`](/llm/markdown/api/commands/tick.md). To freeze the date and control timeouts while leaving animation frames running in real time, list only the functions you want to override.\n\n```\ncy.clock(Date.UTC(2026, 0, 1), ['Date', 'setTimeout', 'clearTimeout'])\n```\n",
      "section": "api",
      "anchors": [
        "freeze-the-date-and-keep-animations-running-with-cy-clock"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 85
    },
    {
      "id": "api/commands/clock#restore-clock",
      "doc_id": "api/commands/clock",
      "heading": "Restore clock",
      "heading_level": 3,
      "content_markdown": "### Restore clock\n\nYou can restore the clock and allow your application to resume normally without manipulating native global functions related to time. This is automatically called between tests.\n\n`clock.restore()` returns native timer APIs (`setTimeout`, `setInterval`, etc.) to the `window`. New timers created _after_ `restore()` run in real time. Timers registered while the fake clock was active are discarded and don't resume automatically. If your application code needs to keep running after `restore()`, it must re-register those timers itself. Timers your application registered before `cy.clock()` was called were never faked, so they keep running in real time.\n\n```\ncy.clock()\ncy.visit('http://localhost:3333')\ncy.get('#search').type('Acme Company')\ncy.tick(1000)\n// more test code here\n\n// restore the clock\ncy.clock().then((clock) => {\n  clock.restore()\n})\n// more test code here\n```\n\nYou could also restore by using [.invoke()](/llm/markdown/api/commands/invoke.md) to invoke the `restore` function.\n\n```\ncy.clock().invoke('restore')\n```\n",
      "section": "api",
      "anchors": [
        "restore-clock"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 184
    },
    {
      "id": "api/commands/clock#change-current-system-time",
      "doc_id": "api/commands/clock",
      "heading": "Change current system time",
      "heading_level": 3,
      "content_markdown": "### Change current system time\n\nThis example tests that a timer still displays correctly after it has run for an hour, without triggering an hour's worth of `setInterval` or `requestAnimationFrame` callbacks and overloading your CPU.\n\n```\ncy.clock(0)\ncy.visit('http://localhost:3333')\ncy.clock().then((clock) => {\n  clock.setSystemTime(60 * 60 * 1000 - 60)\n  // setSystemTime doesn't trigger any timers, so we run the last frame\n  // with tick to trigger a callback to update the timer.\n  clock.tick(60)\n})\n// the timer shows an hour has passed and still fits on the page\ncy.get('#timer').should('contain', '1:00:00').and('be.visible')\n// more test code here\n```\n\nYou could also change the system time by using [.invoke()](/llm/markdown/api/commands/invoke.md) to invoke the `setSystemTime` function.\n\n```\ncy.clock().invoke('setSystemTime', 60 * 60 * 1000)\n```\n",
      "section": "api",
      "anchors": [
        "change-current-system-time"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 157
    },
    {
      "id": "api/commands/clock#notes",
      "doc_id": "api/commands/clock",
      "heading": "Notes",
      "heading_level": 2,
      "content_markdown": "## Notes\n\n### iframes\n\n#### iframes not supported\n\n`cy.clock()` only applies to the `top` window on a web page. It doesn't override the time functions of any `iframe` embedded on the page.\n\n### Behavior\n\n#### CSS animations and transitions ignore `cy.clock()`\n\n`cy.clock()` overrides JavaScript time functions only. CSS animations and CSS transitions run on the browser's own clock, so they keep playing in real time and [`cy.tick()`](/llm/markdown/api/commands/tick.md) doesn't move them forward.\n\n#### clock behavior before `cy.mount()`\n\nUsing the [`cy.mount()`](/llm/markdown/api/commands/mount.md) command in a Cypress Component Test renders your component but doesn't affect the behavior of the page or window object. This means you can `mount` directly after calling `cy.clock()` to test the component against any changes you've made to the yielded clock object.\n\n#### clock behavior before `cy.visit()`\n\nIf you call `cy.clock()` before visiting a page with [`cy.visit()`](/llm/markdown/api/commands/visit.md), Cypress overrides the page's native global functions on window load, before any of your app code runs. So even if `setTimeout`, for example, is called on page load, it can still be controlled via [`cy.tick()`](/llm/markdown/api/commands/tick.md). This also applies if, during the course of a test, the page under test is reloaded or changed.\n\nEach new page gets a fresh fake clock that starts again at the original `now` value (or the unix epoch). Time you advanced with `cy.tick()` on the previous page and timers it registered don't carry over to the new page.\n",
      "section": "api",
      "anchors": [
        "notes"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 307
    },
    {
      "id": "api/commands/clock#iframes",
      "doc_id": "api/commands/clock",
      "heading": "iframes",
      "heading_level": 3,
      "content_markdown": "### iframes\n\n#### iframes not supported\n\n`cy.clock()` only applies to the `top` window on a web page. It doesn't override the time functions of any `iframe` embedded on the page.\n",
      "section": "api",
      "anchors": [
        "iframes"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 40
    },
    {
      "id": "api/commands/clock#behavior",
      "doc_id": "api/commands/clock",
      "heading": "Behavior",
      "heading_level": 3,
      "content_markdown": "### Behavior\n\n#### CSS animations and transitions ignore `cy.clock()`\n\n`cy.clock()` overrides JavaScript time functions only. CSS animations and CSS transitions run on the browser's own clock, so they keep playing in real time and [`cy.tick()`](/llm/markdown/api/commands/tick.md) doesn't move them forward.\n\n#### clock behavior before `cy.mount()`\n\nUsing the [`cy.mount()`](/llm/markdown/api/commands/mount.md) command in a Cypress Component Test renders your component but doesn't affect the behavior of the page or window object. This means you can `mount` directly after calling `cy.clock()` to test the component against any changes you've made to the yielded clock object.\n\n#### clock behavior before `cy.visit()`\n\nIf you call `cy.clock()` before visiting a page with [`cy.visit()`](/llm/markdown/api/commands/visit.md), Cypress overrides the page's native global functions on window load, before any of your app code runs. So even if `setTimeout`, for example, is called on page load, it can still be controlled via [`cy.tick()`](/llm/markdown/api/commands/tick.md). This also applies if, during the course of a test, the page under test is reloaded or changed.\n\nEach new page gets a fresh fake clock that starts again at the original `now` value (or the unix epoch). Time you advanced with `cy.tick()` on the previous page and timers it registered don't carry over to the new page.\n",
      "section": "api",
      "anchors": [
        "behavior"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 264
    },
    {
      "id": "api/commands/clock#css-animations-and-transitions-ignore-cy-clock",
      "doc_id": "api/commands/clock",
      "heading": "CSS animations and transitions ignore cy.clock()",
      "heading_level": 4,
      "content_markdown": "#### CSS animations and transitions ignore `cy.clock()`\n\n`cy.clock()` overrides JavaScript time functions only. CSS animations and CSS transitions run on the browser's own clock, so they keep playing in real time and [`cy.tick()`](/llm/markdown/api/commands/tick.md) doesn't move them forward.\n",
      "section": "api",
      "anchors": [
        "css-animations-and-transitions-ignore-cy-clock"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 49
    },
    {
      "id": "api/commands/clock#clock-behavior-before-cy-mount",
      "doc_id": "api/commands/clock",
      "heading": "clock behavior before cy.mount()",
      "heading_level": 4,
      "content_markdown": "#### clock behavior before `cy.mount()`\n\nUsing the [`cy.mount()`](/llm/markdown/api/commands/mount.md) command in a Cypress Component Test renders your component but doesn't affect the behavior of the page or window object. This means you can `mount` directly after calling `cy.clock()` to test the component against any changes you've made to the yielded clock object.\n",
      "section": "api",
      "anchors": [
        "clock-behavior-before-cy-mount"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 68
    },
    {
      "id": "api/commands/clock#clock-behavior-before-cy-visit",
      "doc_id": "api/commands/clock",
      "heading": "clock behavior before cy.visit()",
      "heading_level": 4,
      "content_markdown": "#### clock behavior before `cy.visit()`\n\nIf you call `cy.clock()` before visiting a page with [`cy.visit()`](/llm/markdown/api/commands/visit.md), Cypress overrides the page's native global functions on window load, before any of your app code runs. So even if `setTimeout`, for example, is called on page load, it can still be controlled via [`cy.tick()`](/llm/markdown/api/commands/tick.md). This also applies if, during the course of a test, the page under test is reloaded or changed.\n\nEach new page gets a fresh fake clock that starts again at the original `now` value (or the unix epoch). Time you advanced with `cy.tick()` on the previous page and timers it registered don't carry over to the new page.\n",
      "section": "api",
      "anchors": [
        "clock-behavior-before-cy-visit"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 144
    },
    {
      "id": "api/commands/clock#rules",
      "doc_id": "api/commands/clock",
      "heading": "Rules",
      "heading_level": 2,
      "content_markdown": "## Rules\n\n### Requirements\n\n*   `cy.clock()` requires being chained off of `cy`.\n\n### Assertions\n\n*   `cy.clock()` is a utility command.\n*   `cy.clock()` will not run assertions. Assertions will pass through as if this command did not exist.\n\n### Timeouts\n\n*   `cy.clock()` cannot time out.\n",
      "section": "api",
      "anchors": [
        "rules"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 59
    },
    {
      "id": "api/commands/clock#command-log",
      "doc_id": "api/commands/clock",
      "heading": "Command Log",
      "heading_level": 2,
      "content_markdown": "## Command Log\n\n**_Create a clock and tick it 1 second_**\n\n```\ncy.clock()\ncy.tick(1000)\n```\n\nThe command above displays in the Command Log as:\n\nWhen clicking on the `clock` command within the command log, the console outputs the following:\n",
      "section": "api",
      "anchors": [
        "command-log"
      ],
      "path": "/llm/json/chunked/api/commands/clock.json",
      "token_estimate": 52
    }
  ]
}