{
  "doc": {
    "id": "api/cypress-api/ensure",
    "title": "Cypress.ensure",
    "description": "Cypress.ensure validates the subject of a custom query or custom command and throws the same errors as the built-in Cypress commands.",
    "section": "api",
    "source_path": "/llm/markdown/api/cypress-api/ensure.md",
    "version": "c4ad6f88c531de58221c73dd91a75af7138334b8",
    "updated_at": "2026-11-10T01:15:02.829Z",
    "headings": [
      {
        "id": "api/cypress-api/ensure#cypress-ensure",
        "text": "Cypress.ensure",
        "level": 1
      },
      {
        "id": "api/cypress-api/ensure#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/cypress-api/ensure#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#return-value",
        "text": "Return value",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#functions",
        "text": "Functions",
        "level": 2
      },
      {
        "id": "api/cypress-api/ensure#isattached",
        "text": "isAttached()",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#isdocument",
        "text": "isDocument()",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#iselement",
        "text": "isElement()",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#isnotdisabled",
        "text": "isNotDisabled()",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#isnothiddenbyancestors",
        "text": "isNotHiddenByAncestors()",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#isnotreadonly",
        "text": "isNotReadonly()",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#isscrollable",
        "text": "isScrollable()",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#istype",
        "text": "isType()",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#isvisible",
        "text": "isVisible()",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#iswindow",
        "text": "isWindow()",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/cypress-api/ensure#compare-a-hand-written-error-with-an-ensure-error",
        "text": "Compare a hand-written error with an ensure error",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#choose-between-an-ensure-check-and-an-assertion",
        "text": "Choose between an ensure check and an assertion",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#accept-only-certain-subject-types-in-a-custom-query",
        "text": "Accept only certain subject types in a custom query",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#wait-for-an-element-to-be-editable-in-a-custom-query",
        "text": "Wait for an element to be editable in a custom query",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#support-a-force-option-in-a-custom-query",
        "text": "Support a force option in a custom query",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#wait-for-a-carousel-slide-to-scroll-into-view",
        "text": "Wait for a carousel slide to scroll into view",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#read-a-documents-meta-tags-in-a-custom-query",
        "text": "Read a document's meta tags in a custom query",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#read-the-apps-localstorage-keys-in-a-custom-query",
        "text": "Read the app's localStorage keys in a custom query",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#check-an-element-before-acting-on-it-in-a-custom-command",
        "text": "Check an element before acting on it in a custom command",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#guard-a-native-dom-call-against-a-detached-element",
        "text": "Guard a native DOM call against a detached element",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#write-your-own-subject-check-in-a-custom-query",
        "text": "Write your own subject check in a custom query",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#notes",
        "text": "Notes",
        "level": 2
      },
      {
        "id": "api/cypress-api/ensure#retry-behavior-of-ensure-checks-in-queries-and-commands",
        "text": "Retry behavior of ensure checks in queries and commands",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#error-messages-come-from-the-built-in-commands",
        "text": "Error messages come from the built-in commands",
        "level": 3
      },
      {
        "id": "api/cypress-api/ensure#history",
        "text": "History",
        "level": 2
      },
      {
        "id": "api/cypress-api/ensure#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/cypress-api/ensure#syntax",
      "doc_id": "api/cypress-api/ensure",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\nCypress.ensure.isAttached(subject, commandName, cy)\nCypress.ensure.isDocument(subject, commandName, cy)\nCypress.ensure.isElement(subject, commandName, cy)\nCypress.ensure.isNotDisabled(subject, commandName)\nCypress.ensure.isNotHiddenByAncestors(subject, commandName)\nCypress.ensure.isNotReadonly(subject, commandName)\nCypress.ensure.isScrollable(subject, commandName)\nCypress.ensure.isType(subject, types, commandName, cy)\nCypress.ensure.isVisible(subject, commandName)\nCypress.ensure.isWindow(subject, commandName, cy)\n```\n\n### Usage\n\n**Correct Usage**\n\n```\nCypress.Commands.addQuery('editable', function () {\n  return (subject) => {\n    Cypress.ensure.isElement(subject, 'editable', cy)\n    Cypress.ensure.isNotDisabled(subject, 'editable')\n\n    return subject\n  }\n})\n```\n\n**Incorrect Usage**\n\n```\n// The state checks take no `cy` argument\nCypress.ensure.isNotDisabled(subject, 'editable', cy)\n\n// The state checks need the jQuery-wrapped subject, not a raw DOM element\nCypress.ensure.isNotDisabled(subject[0], 'editable')\n```\n\n### Arguments\n\nThese arguments are shared by every function. `isType()` also takes a [`types`](#isType) array.\n\n**subject** **_(any)_**\n\nThe value to check, usually the subject your query or command received from the previous command. The element state checks (`isNotDisabled()`, `isNotHiddenByAncestors()`, `isNotReadonly()`, `isScrollable()`, and `isVisible()`) expect a jQuery-wrapped element, which is what [`cy.get()`](/llm/markdown/api/commands/get.md) and other element queries yield.\n\n**commandName** **_(String)_**\n\nThe name of your query or command, as the reader calls it. Cypress puts it in the error message, so `'editable'` produces an error that starts with `` `cy.editable()` failed because… ``.\n\n**cy** **_(Object)_**\n\nThe global [`cy`](/llm/markdown/api/table-of-contents.md) object. Pass it to the type checks and `isAttached()`. Cypress reads the current command chain from it to describe the previous command and the subject in the error.\n\n### Return value\n\nEach function returns nothing when the check passes and throws an error when it fails. `isScrollable()` returns `true` when the check passes.\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 308
    },
    {
      "id": "api/cypress-api/ensure#usage",
      "doc_id": "api/cypress-api/ensure",
      "heading": "Usage",
      "heading_level": 3,
      "content_markdown": "### Usage\n\n**Correct Usage**\n\n```\nCypress.Commands.addQuery('editable', function () {\n  return (subject) => {\n    Cypress.ensure.isElement(subject, 'editable', cy)\n    Cypress.ensure.isNotDisabled(subject, 'editable')\n\n    return subject\n  }\n})\n```\n\n**Incorrect Usage**\n\n```\n// The state checks take no `cy` argument\nCypress.ensure.isNotDisabled(subject, 'editable', cy)\n\n// The state checks need the jQuery-wrapped subject, not a raw DOM element\nCypress.ensure.isNotDisabled(subject[0], 'editable')\n```\n",
      "section": "api",
      "anchors": [
        "usage"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 71
    },
    {
      "id": "api/cypress-api/ensure#arguments",
      "doc_id": "api/cypress-api/ensure",
      "heading": "Arguments",
      "heading_level": 3,
      "content_markdown": "### Arguments\n\nThese arguments are shared by every function. `isType()` also takes a [`types`](#isType) array.\n\n**subject** **_(any)_**\n\nThe value to check, usually the subject your query or command received from the previous command. The element state checks (`isNotDisabled()`, `isNotHiddenByAncestors()`, `isNotReadonly()`, `isScrollable()`, and `isVisible()`) expect a jQuery-wrapped element, which is what [`cy.get()`](/llm/markdown/api/commands/get.md) and other element queries yield.\n\n**commandName** **_(String)_**\n\nThe name of your query or command, as the reader calls it. Cypress puts it in the error message, so `'editable'` produces an error that starts with `` `cy.editable()` failed because… ``.\n\n**cy** **_(Object)_**\n\nThe global [`cy`](/llm/markdown/api/table-of-contents.md) object. Pass it to the type checks and `isAttached()`. Cypress reads the current command chain from it to describe the previous command and the subject in the error.\n",
      "section": "api",
      "anchors": [
        "arguments"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 164
    },
    {
      "id": "api/cypress-api/ensure#functions",
      "doc_id": "api/cypress-api/ensure",
      "heading": "Functions",
      "heading_level": 2,
      "content_markdown": "## Functions\n\n| Function | Throws when the subject… |\n| --- | --- |\n| [`isAttached()`](#isAttached) | is a DOM element no longer attached to the page |\n| [`isDocument()`](#isDocument) | is not a `document` |\n| [`isElement()`](#isElement) | is not a DOM element |\n| [`isNotDisabled()`](#isNotDisabled) | is disabled |\n| [`isNotHiddenByAncestors()`](#isNotHiddenByAncestors) | is clipped out of view by an ancestor's `overflow` |\n| [`isNotReadonly()`](#isNotReadonly) | is a read-only text field |\n| [`isScrollable()`](#isScrollable) | cannot be scrolled |\n| [`isType()`](#isType) | matches none of the listed `types` |\n| [`isVisible()`](#isVisible) | is not visible |\n| [`isWindow()`](#isWindow) | is not a `window` |\n\n### isAttached()\n\n```\nCypress.ensure.isAttached(subject, commandName, cy)\n```\n\nThrows when the subject is a DOM element that is no longer attached to the page, for example because the app re-rendered it. Use it before you call a native DOM method on an element you've held onto. On a detached element, a native call such as `.click()` acts on the stale element instead of the one on the page, and raises no error.\n\nWhen the check fails, it throws:\n\n```\n`cy.<commandName>()` failed because the page updated as a result of this command, but you tried to continue the command chain.\n```\n\nUsed in: [Guard a native DOM call against a detached element](#Guard-a-native-DOM-call-against-a-detached-element)\n\n### isDocument()\n\n```\nCypress.ensure.isDocument(subject, commandName, cy)\n```\n\nThrows when the subject is not a global `document` object, such as the one [`cy.document()`](/llm/markdown/api/commands/document.md) yields.\n\nWhen the check fails, it throws:\n\n```\n`cy.<commandName>()` failed because it requires the subject be a global `document` object.\n```\n\nUsed in: [Read a document's meta tags in a custom query](#Read-a-documents-meta-tags-in-a-custom-query)\n\n### isElement()\n\n```\nCypress.ensure.isElement(subject, commandName, cy)\n```\n\nThrows when the subject is not a DOM element or a jQuery collection of them. Unlike `isType(subject, ['element'], …)`, it doesn't check that the element is still attached; pair it with [`isAttached()`](#isAttached) when that matters.\n\nWhen the check fails, it throws this error, followed by the subject received and the previous command:\n\n```\n`cy.<commandName>()` failed because it requires a DOM element.\n```\n\nUsed in: [Compare a hand-written error with an ensure error](#Compare-a-hand-written-error-with-an-ensure-error), [Wait for an element to be editable in a custom query](#Wait-for-an-element-to-be-editable-in-a-custom-query), [Wait for a carousel slide to scroll into view](#Wait-for-a-carousel-slide-to-scroll-into-view)\n\n### isNotDisabled()\n\n```\nCypress.ensure.isNotDisabled(subject, commandName)\n```\n\nThrows when the subject has the `disabled` property, the same check [`.select()`](/llm/markdown/api/commands/select.md) and [`.selectFile()`](/llm/markdown/api/commands/selectfile.md) run.\n\n*   When the subject is a collection, it checks only the first element.\n\nWhen the check fails, it throws:\n\n```\n`cy.<commandName>()` failed because this element is `disabled`:\n```\n\nUsed in: [Wait for an element to be editable in a custom query](#Wait-for-an-element-to-be-editable-in-a-custom-query)\n\n### isNotHiddenByAncestors()\n\n```\nCypress.ensure.isNotHiddenByAncestors(subject, commandName)\n```\n\nThrows when an ancestor clips the subject out of view, such as an `overflow: hidden` container the element has scrolled outside of, or a zero-height container with `overflow: hidden`. It also fails a `fixed` or `sticky` element that another element covers.\n\nIt doesn't check the ancestors' `display` or `visibility`, so an element inside a `display: none` parent passes. Call [`isVisible()`](#isVisible) for that. Cypress runs this check after `isVisible()` when the [`visibilityStrategy`](/llm/markdown/app/core-concepts/interacting-with-elements.md#Visibility-Strategy) is `'legacy'`.\n\n*   It treats `opacity: 0` as visible.\n*   When the subject is a collection, it fails when any element is clipped.\n\nWhen the check fails, it throws this error, followed by the reason:\n\n```\n`cy.<commandName>()` failed because this element is not visible:\n```\n\nUsed in: [Wait for a carousel slide to scroll into view](#Wait-for-a-carousel-slide-to-scroll-into-view)\n\n### isNotReadonly()\n\n```\nCypress.ensure.isNotReadonly(subject, commandName)\n```\n\nThrows when the subject is a text-like element, such as `<input type=\"text\">`, `<input type=\"email\">`, or `<textarea>`, with the `readonly` attribute. A checkbox, radio button, or other element with `readonly` passes, because browsers ignore `readonly` on those elements.\n\n*   When the subject is a collection, it checks only the first element.\n\nWhen the check fails, it throws:\n\n```\n`cy.<commandName>()` failed because this element is readonly:\n```\n\nUsed in: [Wait for an element to be editable in a custom query](#Wait-for-an-element-to-be-editable-in-a-custom-query)\n\n### isScrollable()\n\n```\nCypress.ensure.isScrollable(subject, commandName)\n```\n\nThrows when the subject cannot be scrolled, the same check [`.scrollTo()`](/llm/markdown/api/commands/scrollto.md) runs. Returns `true` when it passes.\n\nWhen the check fails, it throws:\n\n```\n`cy.<commandName>()` failed because this element is not scrollable:\n```\n\nUsed in: [Check an element before acting on it in a custom command](#Check-an-element-before-acting-on-it-in-a-custom-command)\n\n### isType()\n\n```\nCypress.ensure.isType(subject, types, commandName, cy)\n```\n\nThrows when the subject matches none of the `types`. This is the check behind a custom command's [`prevSubject`](/llm/markdown/api/cypress-api/custom-commands.md#Validations) option.\n\n**types** **_(Array)_**\n\nAny of `'element'`, `'document'`, `'window'`, and `'optional'`. The check passes when the subject matches at least one of them.\n\n*   `'optional'` lets an `undefined` subject through, for a query that can start a chain or continue one.\n*   `'element'` also runs [`isAttached()`](#isAttached), so a subject the app has removed from the page fails with the detached-element error.\n*   When you list more than one type, the error names all of them.\n\nWith `['element', 'document']`, a failed check throws:\n\n```\n`cy.<commandName>()` failed because it requires a DOM element or document.\n```\n\nUsed in: [Accept only certain subject types in a custom query](#Accept-only-certain-subject-types-in-a-custom-query)\n\n### isVisible()\n\n```\nCypress.ensure.isVisible(subject, commandName)\n```\n\nThrows when the subject is not visible, following the [visibility rules](/llm/markdown/app/core-concepts/interacting-with-elements.md#Visibility) of your [`visibilityStrategy`](/llm/markdown/app/core-concepts/interacting-with-elements.md#Visibility-Strategy).\n\n*   It treats `opacity: 0` as visible, matching the checks Cypress runs before it interacts with an element. Assert with `.should('be.visible')` when opacity matters.\n*   When the subject is a collection, it fails when any element is hidden.\n\nWhen the check fails, it throws this error, followed by the reason:\n\n```\n`cy.<commandName>()` failed because this element is not visible:\n```\n\nUsed in: [Wait for an element to be editable in a custom query](#Wait-for-an-element-to-be-editable-in-a-custom-query)\n\n### isWindow()\n\n```\nCypress.ensure.isWindow(subject, commandName, cy)\n```\n\nThrows when the subject is not a global `window` object, such as the one [`cy.window()`](/llm/markdown/api/commands/window.md) yields.\n\nWhen the check fails, it throws:\n\n```\n`cy.<commandName>()` failed because it requires the subject be a global `window` object.\n```\n\nUsed in: [Read the app's localStorage keys in a custom query](#Read-the-apps-localStorage-keys-in-a-custom-query)\n",
      "section": "api",
      "anchors": [
        "functions"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 1303
    },
    {
      "id": "api/cypress-api/ensure#isattached",
      "doc_id": "api/cypress-api/ensure",
      "heading": "isAttached()",
      "heading_level": 3,
      "content_markdown": "### isAttached()\n\n```\nCypress.ensure.isAttached(subject, commandName, cy)\n```\n\nThrows when the subject is a DOM element that is no longer attached to the page, for example because the app re-rendered it. Use it before you call a native DOM method on an element you've held onto. On a detached element, a native call such as `.click()` acts on the stale element instead of the one on the page, and raises no error.\n\nWhen the check fails, it throws:\n\n```\n`cy.<commandName>()` failed because the page updated as a result of this command, but you tried to continue the command chain.\n```\n\nUsed in: [Guard a native DOM call against a detached element](#Guard-a-native-DOM-call-against-a-detached-element)\n",
      "section": "api",
      "anchors": [
        "isattached"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 147
    },
    {
      "id": "api/cypress-api/ensure#isdocument",
      "doc_id": "api/cypress-api/ensure",
      "heading": "isDocument()",
      "heading_level": 3,
      "content_markdown": "### isDocument()\n\n```\nCypress.ensure.isDocument(subject, commandName, cy)\n```\n\nThrows when the subject is not a global `document` object, such as the one [`cy.document()`](/llm/markdown/api/commands/document.md) yields.\n\nWhen the check fails, it throws:\n\n```\n`cy.<commandName>()` failed because it requires the subject be a global `document` object.\n```\n\nUsed in: [Read a document's meta tags in a custom query](#Read-a-documents-meta-tags-in-a-custom-query)\n",
      "section": "api",
      "anchors": [
        "isdocument"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 72
    },
    {
      "id": "api/cypress-api/ensure#iselement",
      "doc_id": "api/cypress-api/ensure",
      "heading": "isElement()",
      "heading_level": 3,
      "content_markdown": "### isElement()\n\n```\nCypress.ensure.isElement(subject, commandName, cy)\n```\n\nThrows when the subject is not a DOM element or a jQuery collection of them. Unlike `isType(subject, ['element'], …)`, it doesn't check that the element is still attached; pair it with [`isAttached()`](#isAttached) when that matters.\n\nWhen the check fails, it throws this error, followed by the subject received and the previous command:\n\n```\n`cy.<commandName>()` failed because it requires a DOM element.\n```\n\nUsed in: [Compare a hand-written error with an ensure error](#Compare-a-hand-written-error-with-an-ensure-error), [Wait for an element to be editable in a custom query](#Wait-for-an-element-to-be-editable-in-a-custom-query), [Wait for a carousel slide to scroll into view](#Wait-for-a-carousel-slide-to-scroll-into-view)\n",
      "section": "api",
      "anchors": [
        "iselement"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 132
    },
    {
      "id": "api/cypress-api/ensure#isnotdisabled",
      "doc_id": "api/cypress-api/ensure",
      "heading": "isNotDisabled()",
      "heading_level": 3,
      "content_markdown": "### isNotDisabled()\n\n```\nCypress.ensure.isNotDisabled(subject, commandName)\n```\n\nThrows when the subject has the `disabled` property, the same check [`.select()`](/llm/markdown/api/commands/select.md) and [`.selectFile()`](/llm/markdown/api/commands/selectfile.md) run.\n\n*   When the subject is a collection, it checks only the first element.\n\nWhen the check fails, it throws:\n\n```\n`cy.<commandName>()` failed because this element is `disabled`:\n```\n\nUsed in: [Wait for an element to be editable in a custom query](#Wait-for-an-element-to-be-editable-in-a-custom-query)\n",
      "section": "api",
      "anchors": [
        "isnotdisabled"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 83
    },
    {
      "id": "api/cypress-api/ensure#isnothiddenbyancestors",
      "doc_id": "api/cypress-api/ensure",
      "heading": "isNotHiddenByAncestors()",
      "heading_level": 3,
      "content_markdown": "### isNotHiddenByAncestors()\n\n```\nCypress.ensure.isNotHiddenByAncestors(subject, commandName)\n```\n\nThrows when an ancestor clips the subject out of view, such as an `overflow: hidden` container the element has scrolled outside of, or a zero-height container with `overflow: hidden`. It also fails a `fixed` or `sticky` element that another element covers.\n\nIt doesn't check the ancestors' `display` or `visibility`, so an element inside a `display: none` parent passes. Call [`isVisible()`](#isVisible) for that. Cypress runs this check after `isVisible()` when the [`visibilityStrategy`](/llm/markdown/app/core-concepts/interacting-with-elements.md#Visibility-Strategy) is `'legacy'`.\n\n*   It treats `opacity: 0` as visible.\n*   When the subject is a collection, it fails when any element is clipped.\n\nWhen the check fails, it throws this error, followed by the reason:\n\n```\n`cy.<commandName>()` failed because this element is not visible:\n```\n\nUsed in: [Wait for a carousel slide to scroll into view](#Wait-for-a-carousel-slide-to-scroll-into-view)\n",
      "section": "api",
      "anchors": [
        "isnothiddenbyancestors"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 177
    },
    {
      "id": "api/cypress-api/ensure#isnotreadonly",
      "doc_id": "api/cypress-api/ensure",
      "heading": "isNotReadonly()",
      "heading_level": 3,
      "content_markdown": "### isNotReadonly()\n\n```\nCypress.ensure.isNotReadonly(subject, commandName)\n```\n\nThrows when the subject is a text-like element, such as `<input type=\"text\">`, `<input type=\"email\">`, or `<textarea>`, with the `readonly` attribute. A checkbox, radio button, or other element with `readonly` passes, because browsers ignore `readonly` on those elements.\n\n*   When the subject is a collection, it checks only the first element.\n\nWhen the check fails, it throws:\n\n```\n`cy.<commandName>()` failed because this element is readonly:\n```\n\nUsed in: [Wait for an element to be editable in a custom query](#Wait-for-an-element-to-be-editable-in-a-custom-query)\n",
      "section": "api",
      "anchors": [
        "isnotreadonly"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 112
    },
    {
      "id": "api/cypress-api/ensure#isscrollable",
      "doc_id": "api/cypress-api/ensure",
      "heading": "isScrollable()",
      "heading_level": 3,
      "content_markdown": "### isScrollable()\n\n```\nCypress.ensure.isScrollable(subject, commandName)\n```\n\nThrows when the subject cannot be scrolled, the same check [`.scrollTo()`](/llm/markdown/api/commands/scrollto.md) runs. Returns `true` when it passes.\n\nWhen the check fails, it throws:\n\n```\n`cy.<commandName>()` failed because this element is not scrollable:\n```\n\nUsed in: [Check an element before acting on it in a custom command](#Check-an-element-before-acting-on-it-in-a-custom-command)\n",
      "section": "api",
      "anchors": [
        "isscrollable"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 69
    },
    {
      "id": "api/cypress-api/ensure#istype",
      "doc_id": "api/cypress-api/ensure",
      "heading": "isType()",
      "heading_level": 3,
      "content_markdown": "### isType()\n\n```\nCypress.ensure.isType(subject, types, commandName, cy)\n```\n\nThrows when the subject matches none of the `types`. This is the check behind a custom command's [`prevSubject`](/llm/markdown/api/cypress-api/custom-commands.md#Validations) option.\n\n**types** **_(Array)_**\n\nAny of `'element'`, `'document'`, `'window'`, and `'optional'`. The check passes when the subject matches at least one of them.\n\n*   `'optional'` lets an `undefined` subject through, for a query that can start a chain or continue one.\n*   `'element'` also runs [`isAttached()`](#isAttached), so a subject the app has removed from the page fails with the detached-element error.\n*   When you list more than one type, the error names all of them.\n\nWith `['element', 'document']`, a failed check throws:\n\n```\n`cy.<commandName>()` failed because it requires a DOM element or document.\n```\n\nUsed in: [Accept only certain subject types in a custom query](#Accept-only-certain-subject-types-in-a-custom-query)\n",
      "section": "api",
      "anchors": [
        "istype"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 173
    },
    {
      "id": "api/cypress-api/ensure#isvisible",
      "doc_id": "api/cypress-api/ensure",
      "heading": "isVisible()",
      "heading_level": 3,
      "content_markdown": "### isVisible()\n\n```\nCypress.ensure.isVisible(subject, commandName)\n```\n\nThrows when the subject is not visible, following the [visibility rules](/llm/markdown/app/core-concepts/interacting-with-elements.md#Visibility) of your [`visibilityStrategy`](/llm/markdown/app/core-concepts/interacting-with-elements.md#Visibility-Strategy).\n\n*   It treats `opacity: 0` as visible, matching the checks Cypress runs before it interacts with an element. Assert with `.should('be.visible')` when opacity matters.\n*   When the subject is a collection, it fails when any element is hidden.\n\nWhen the check fails, it throws this error, followed by the reason:\n\n```\n`cy.<commandName>()` failed because this element is not visible:\n```\n\nUsed in: [Wait for an element to be editable in a custom query](#Wait-for-an-element-to-be-editable-in-a-custom-query)\n",
      "section": "api",
      "anchors": [
        "isvisible"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 124
    },
    {
      "id": "api/cypress-api/ensure#iswindow",
      "doc_id": "api/cypress-api/ensure",
      "heading": "isWindow()",
      "heading_level": 3,
      "content_markdown": "### isWindow()\n\n```\nCypress.ensure.isWindow(subject, commandName, cy)\n```\n\nThrows when the subject is not a global `window` object, such as the one [`cy.window()`](/llm/markdown/api/commands/window.md) yields.\n\nWhen the check fails, it throws:\n\n```\n`cy.<commandName>()` failed because it requires the subject be a global `window` object.\n```\n\nUsed in: [Read the app's localStorage keys in a custom query](#Read-the-apps-localStorage-keys-in-a-custom-query)\n",
      "section": "api",
      "anchors": [
        "iswindow"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 72
    },
    {
      "id": "api/cypress-api/ensure#examples",
      "doc_id": "api/cypress-api/ensure",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\n### Compare a hand-written error with an ensure error\n\nBoth versions of the `.inputValue()` query below reject a subject that isn't an element. The first throws its own error:\n\n*   JavaScript\n*   TypeScript\n\ncypress/support/commands.js\n\n```\nCypress.Commands.addQuery('inputValue', function () {\n  return (subject) => {\n    if (!Cypress.dom.isElement(subject)) {\n      throw new Error('inputValue() requires an element')\n    }\n\n    return subject.val()\n  }\n})\nexport {}\n```\n\ncypress/support/commands.ts\n\n```\ndeclare global {\n  namespace Cypress {\n    interface Chainable {\n      inputValue(): Chainable<string | number | string[] | undefined>\n    }\n  }\n}\n\nCypress.Commands.addQuery('inputValue', function () {\n  return (subject) => {\n    if (!Cypress.dom.isElement(subject)) {\n      throw new Error('inputValue() requires an element')\n    }\n\n    return subject.val()\n  }\n})\n\nexport {}\n```\n\nThe second calls `Cypress.ensure.isElement()` instead:\n\n*   JavaScript\n*   TypeScript\n\ncypress/support/commands.js\n\n```\nCypress.Commands.addQuery('inputValue', function () {\n  return (subject) => {\n    Cypress.ensure.isElement(subject, 'inputValue', cy)\n\n    return subject.val()\n  }\n})\nexport {}\n```\n\ncypress/support/commands.ts\n\n```\ndeclare global {\n  namespace Cypress {\n    interface Chainable {\n      inputValue(): Chainable<string | number | string[] | undefined>\n    }\n  }\n}\n\nCypress.Commands.addQuery('inputValue', function () {\n  return (subject) => {\n    Cypress.ensure.isElement(subject, 'inputValue', cy)\n\n    return subject.val()\n  }\n})\n\nexport {}\n```\n\nChain either one off a subject that isn't an element:\n\ncypress/e2e/profile.cy.js\n\n```\ncy.title().inputValue()\n```\n\nThe hand-written check fails with only its own message:\n\n```\nError: Timed out retrying after 4000ms: inputValue() requires an element\n```\n\nThe `ensure` check fails with a Cypress error that names the command, shows the subject it received, and names the command that produced it:\n\n```\nCypressError: Timed out retrying after 4000ms: `cy.inputValue()` failed because it requires a DOM element.\n\nThe subject received was:\n\n  > `Example page`\n\nThe previous command that ran was:\n\n  > `cy.title()`\n```\n\n### Choose between an ensure check and an assertion\n\n`Cypress.ensure` and assertions can check the same state, but they belong in different places. In a test, assert the state you expect with [`.should()`](/llm/markdown/api/commands/should.md). Inside a custom query or command, call `Cypress.ensure`, so every test that uses the query gets the check, and the error names the query:\n\ncypress/e2e/profile.cy.js\n\n```\n// In a test: assert the state you expect\ncy.get('#email').should('be.enabled')\n\n// In a custom query: the check is part of the query\ncy.get('#email').editable()\n```\n\n`.editable()` is defined in [Wait for an element to be editable in a custom query](#Wait-for-an-element-to-be-editable-in-a-custom-query).\n\n### Accept only certain subject types in a custom query\n\nThe `.dataCy()` query below finds elements by their `data-cy` attribute. It can start a chain, where it searches the whole page, or continue one, where it searches inside the previous element or document. `isType()` rejects every other subject, such as a string yielded by [`.invoke()`](/llm/markdown/api/commands/invoke.md).\n\n*   JavaScript\n*   TypeScript\n\ncypress/support/commands.js\n\n```\nCypress.Commands.addQuery('dataCy', function (value) {\n  return (subject) => {\n    Cypress.ensure.isType(\n      subject,\n      ['optional', 'element', 'document'],\n      'dataCy',\n      cy\n    )\n\n    const $root = subject === undefined ? cy.$$('body') : Cypress.$(subject)\n\n    return $root.find(`[data-cy=\"${value}\"]`)\n  }\n})\nexport {}\n```\n\ncypress/support/commands.ts\n\n```\ndeclare global {\n  namespace Cypress {\n    interface Chainable {\n      dataCy(value: string): Chainable<JQuery<HTMLElement>>\n    }\n  }\n}\n\nCypress.Commands.addQuery('dataCy', function (value: string) {\n  return (subject) => {\n    Cypress.ensure.isType(\n      subject,\n      ['optional', 'element', 'document'],\n      'dataCy',\n      cy\n    )\n\n    const $root = subject === undefined ? cy.$$('body') : Cypress.$(subject)\n\n    return $root.find(`[data-cy=\"${value}\"]`)\n  }\n})\n\nexport {}\n```\n\nThen use it at the start of a chain or after another query:\n\ncypress/e2e/data-cy.cy.js\n\n```\ncy.dataCy('submit').should('have.text', 'Submit')\ncy.get('form').dataCy('email').should('have.attr', 'type', 'email')\n```\n\nChaining `.dataCy()` off a subject it doesn't accept fails with a Cypress error that lists every accepted type:\n\ncypress/e2e/data-cy.cy.js\n\n```\ncy.title().dataCy('submit')\n```\n\n```\nCypressError: Timed out retrying after 4000ms: `cy.dataCy()` failed because it requires a DOM element or document.\n\nThe subject received was:\n\n  > `Example page`\n\nThe previous command that ran was:\n\n  > `cy.title()`\n```\n\n### Wait for an element to be editable in a custom query\n\nCypress retries the checks inside a custom query, so a query built from `Cypress.ensure` functions waits for the element to reach the state you need. The `.editable()` query yields its subject once it is visible, enabled, and not read-only, and fails with Cypress's own actionability error if it never gets there.\n\n*   JavaScript\n*   TypeScript\n\ncypress/support/commands.js\n\n```\nCypress.Commands.addQuery('editable', function () {\n  return (subject) => {\n    Cypress.ensure.isElement(subject, 'editable', cy)\n    Cypress.ensure.isVisible(subject, 'editable')\n    Cypress.ensure.isNotDisabled(subject, 'editable')\n    Cypress.ensure.isNotReadonly(subject, 'editable')\n\n    return subject\n  }\n})\nexport {}\n```\n\ncypress/support/commands.ts\n\n```\ndeclare global {\n  namespace Cypress {\n    interface Chainable {\n      editable(): Chainable<JQuery<HTMLElement>>\n    }\n  }\n}\n\nCypress.Commands.addQuery('editable', function () {\n  return (subject) => {\n    Cypress.ensure.isElement(subject, 'editable', cy)\n    Cypress.ensure.isVisible(subject, 'editable')\n    Cypress.ensure.isNotDisabled(subject, 'editable')\n    Cypress.ensure.isNotReadonly(subject, 'editable')\n\n    return subject\n  }\n})\n\nexport {}\n```\n\nHere, the `#email` input starts out disabled and the app enables it after it loads the user's profile. `.editable()` retries until the input is enabled, then [`.invoke()`](/llm/markdown/api/commands/invoke.md) sets its value:\n\ncypress/e2e/profile.cy.js\n\n```\ncy.get('#email').editable().invoke('val', 'jane@example.com')\ncy.get('#email').should('have.value', 'jane@example.com')\n```\n\nIf the input stays disabled, the query times out with the same error a [`.type()`](/llm/markdown/api/commands/type.md) into a disabled input produces:\n\n```\nCypressError: Timed out retrying after 4000ms: `cy.editable()` failed because this element is `disabled`:\n\n`<input id=\"email\" type=\"email\" disabled=\"\">`\n\nFix this problem, or use `{force: true}` to disable error checking.\n\nhttps://on.cypress.io/element-cannot-be-interacted-with\n```\n\nIn the Cypress App, the error appears under the failed test and names `cy.editable()`, the same way it names a built-in command:\n\n### Support a force option in a custom query\n\nSome `ensure` errors end with `use {force: true} to disable error checking`, a hint written for built-in commands such as [`.type()`](/llm/markdown/api/commands/type.md). To make that hint true for your own query, accept a `force` option and skip the state checks when it's set. This version of `.editable()` keeps the type check either way:\n\n*   JavaScript\n*   TypeScript\n\ncypress/support/commands.js\n\n```\nCypress.Commands.addQuery('editable', function (options = {}) {\n  return (subject) => {\n    Cypress.ensure.isElement(subject, 'editable', cy)\n\n    if (!options.force) {\n      Cypress.ensure.isVisible(subject, 'editable')\n      Cypress.ensure.isNotDisabled(subject, 'editable')\n      Cypress.ensure.isNotReadonly(subject, 'editable')\n    }\n\n    return subject\n  }\n})\nexport {}\n```\n\ncypress/support/commands.ts\n\n```\ndeclare global {\n  namespace Cypress {\n    interface Chainable {\n      editable(options?: { force?: boolean }): Chainable<JQuery<HTMLElement>>\n    }\n  }\n}\n\nCypress.Commands.addQuery(\n  'editable',\n  function (options: { force?: boolean } = {}) {\n    return (subject) => {\n      Cypress.ensure.isElement(subject, 'editable', cy)\n\n      if (!options.force) {\n        Cypress.ensure.isVisible(subject, 'editable')\n        Cypress.ensure.isNotDisabled(subject, 'editable')\n        Cypress.ensure.isNotReadonly(subject, 'editable')\n      }\n\n      return subject\n    }\n  }\n)\n\nexport {}\n```\n\nWith `{ force: true }`, the query yields the disabled `#locked` input right away, and `.invoke()` sets its value:\n\ncypress/e2e/profile.cy.js\n\n```\ncy.get('#locked').editable({ force: true }).invoke('val', 'jane@example.com')\n```\n\n### Wait for a carousel slide to scroll into view\n\nAn element scrolled outside an `overflow: hidden` container is still in the page, but the reader can't see it. The `.unclipped()` query retries until no ancestor clips its subject:\n\n*   JavaScript\n*   TypeScript\n\ncypress/support/commands.js\n\n```\nCypress.Commands.addQuery('unclipped', function () {\n  return (subject) => {\n    Cypress.ensure.isElement(subject, 'unclipped', cy)\n    Cypress.ensure.isNotHiddenByAncestors(subject, 'unclipped')\n\n    return subject\n  }\n})\nexport {}\n```\n\ncypress/support/commands.ts\n\n```\ndeclare global {\n  namespace Cypress {\n    interface Chainable {\n      unclipped(): Chainable<JQuery<HTMLElement>>\n    }\n  }\n}\n\nCypress.Commands.addQuery('unclipped', function () {\n  return (subject) => {\n    Cypress.ensure.isElement(subject, 'unclipped', cy)\n    Cypress.ensure.isNotHiddenByAncestors(subject, 'unclipped')\n\n    return subject\n  }\n})\n\nexport {}\n```\n\nHere, clicking `\"Next\"` scrolls the carousel to the second slide. `.unclipped()` waits for the scroll to finish before the assertion runs:\n\ncypress/e2e/carousel.cy.js\n\n```\ncy.get('#next').click()\ncy.contains('.slide', 'Slide 2').unclipped().should('have.text', 'Slide 2')\n```\n\n### Read a document's meta tags in a custom query\n\nThe `.metaContent()` query reads a `<meta>` tag from the [`cy.document()`](/llm/markdown/api/commands/document.md) subject, and `isDocument()` rejects any other subject. Because it's a query, an assertion on its value retries until the app updates the tag:\n\n*   JavaScript\n*   TypeScript\n\ncypress/support/commands.js\n\n```\nCypress.Commands.addQuery('metaContent', function (name) {\n  return (subject) => {\n    Cypress.ensure.isDocument(subject, 'metaContent', cy)\n\n    return subject\n      .querySelector(`meta[name=\"${name}\"]`)\n      ?.getAttribute('content')\n  }\n})\nexport {}\n```\n\ncypress/support/commands.ts\n\n```\ndeclare global {\n  namespace Cypress {\n    interface Chainable {\n      metaContent(name: string): Chainable<string | null | undefined>\n    }\n  }\n}\n\nCypress.Commands.addQuery('metaContent', function (name: string) {\n  return (subject) => {\n    Cypress.ensure.isDocument(subject, 'metaContent', cy)\n\n    return subject\n      .querySelector(`meta[name=\"${name}\"]`)\n      ?.getAttribute('content')\n  }\n})\n\nexport {}\n```\n\ncypress/e2e/seo.cy.js\n\n```\ncy.document().metaContent('description').should('eq', 'Cypress example app')\n```\n\n### Read the app's localStorage keys in a custom query\n\nThe `.storageKeys()` query reads the keys in the app's `localStorage` from the [`cy.window()`](/llm/markdown/api/commands/window.md) subject, and retries until an assertion on them passes:\n\n*   JavaScript\n*   TypeScript\n\ncypress/support/commands.js\n\n```\nCypress.Commands.addQuery('storageKeys', function () {\n  return (subject) => {\n    Cypress.ensure.isWindow(subject, 'storageKeys', cy)\n\n    return Object.keys(subject.localStorage)\n  }\n})\nexport {}\n```\n\ncypress/support/commands.ts\n\n```\ndeclare global {\n  namespace Cypress {\n    interface Chainable {\n      storageKeys(): Chainable<string[]>\n    }\n  }\n}\n\nCypress.Commands.addQuery('storageKeys', function () {\n  return (subject) => {\n    Cypress.ensure.isWindow(subject, 'storageKeys', cy)\n\n    return Object.keys(subject.localStorage)\n  }\n})\n\nexport {}\n```\n\ncypress/e2e/auth.cy.js\n\n```\ncy.window().storageKeys().should('include', 'authToken')\n```\n\n### Check an element before acting on it in a custom command\n\nA custom command added with [`Cypress.Commands.add()`](/llm/markdown/api/cypress-api/custom-commands.md) runs once and is not retried, so a failed check fails the test right away. The `.scrollToBottom()` command below checks that its subject can be scrolled before it changes the element's `scrollTop`, then yields the element so the chain can continue.\n\n*   JavaScript\n*   TypeScript\n\ncypress/support/commands.js\n\n```\nCypress.Commands.add(\n  'scrollToBottom',\n  { prevSubject: 'element' },\n  (subject) => {\n    Cypress.ensure.isScrollable(subject, 'scrollToBottom')\n\n    subject[0].scrollTop = subject[0].scrollHeight\n\n    return cy.wrap(subject, { log: false })\n  }\n)\nexport {}\n```\n\ncypress/support/commands.ts\n\n```\ndeclare global {\n  namespace Cypress {\n    interface Chainable {\n      scrollToBottom(): Chainable<JQuery<HTMLElement>>\n    }\n  }\n}\n\nCypress.Commands.add(\n  'scrollToBottom',\n  { prevSubject: 'element' },\n  (subject) => {\n    Cypress.ensure.isScrollable(subject, 'scrollToBottom')\n\n    subject[0].scrollTop = subject[0].scrollHeight\n\n    return cy.wrap(subject, { log: false })\n  }\n)\n\nexport {}\n```\n\ncypress/e2e/messages.cy.js\n\n```\ncy.get('#messages')\n  .scrollToBottom()\n  .contains('Latest message')\n  .should('be.visible')\n```\n\nCalling it on an element that can't scroll fails with:\n\n```\nCypressError: `cy.scrollToBottom()` failed because this element is not scrollable:\n\n`<div id=\"footer\">Footer</div>`\n\nMake sure you're targeting the correct element or use `{ensureScrollable: false}` to disable the scrollable check.\n\nhttps://on.cypress.io/scrollto\n```\n\nThe message ends with the hint and docs link Cypress shows for its own [`.scrollTo()`](/llm/markdown/api/commands/scrollto.md) command. See [Error messages come from the built-in commands](#Error-messages-come-from-the-built-in-commands).\n\n### Guard a native DOM call against a detached element\n\nThe `.saveAndCollapse()` command clicks a panel's `\"Save\"` button, then clicks its `\"Collapse\"` button with a native DOM `click()`. Saving can re-render the panel, which leaves `subject` pointing at a detached element, and a native click on it never reaches the panel on the page. `isAttached()` turns that silent miss into a clear failure:\n\n*   JavaScript\n*   TypeScript\n\ncypress/support/commands.js\n\n```\nCypress.Commands.add(\n  'saveAndCollapse',\n  { prevSubject: 'element' },\n  (subject) => {\n    cy.wrap(subject).contains('button', 'Save').click()\n\n    cy.then(() => {\n      // Saving can re-render the panel and detach `subject`\n      Cypress.ensure.isAttached(subject, 'saveAndCollapse', cy)\n\n      subject.find('[data-cy=\"collapse\"]')[0].click()\n    })\n  }\n)\nexport {}\n```\n\ncypress/support/commands.ts\n\n```\ndeclare global {\n  namespace Cypress {\n    interface Chainable {\n      saveAndCollapse(): Chainable<void>\n    }\n  }\n}\n\nCypress.Commands.add(\n  'saveAndCollapse',\n  { prevSubject: 'element' },\n  (subject) => {\n    cy.wrap(subject).contains('button', 'Save').click()\n\n    cy.then(() => {\n      // Saving can re-render the panel and detach `subject`\n      Cypress.ensure.isAttached(subject, 'saveAndCollapse', cy)\n\n      subject.find('[data-cy=\"collapse\"]')[0].click()\n    })\n  }\n)\n\nexport {}\n```\n\ncypress/e2e/settings.cy.js\n\n```\ncy.get('#panel').saveAndCollapse()\n```\n\n### Write your own subject check in a custom query\n\n`Cypress.ensure` covers the subject checks Cypress itself needs. For any other condition, throw an error from your query's inner function. Cypress retries it the same way it retries an `ensure` check:\n\n*   JavaScript\n*   TypeScript\n\ncypress/support/commands.js\n\n```\nCypress.Commands.addQuery('priceValue', function () {\n  return (subject) => {\n    Cypress.ensure.isElement(subject, 'priceValue', cy)\n\n    const value = parseFloat(subject.text().replace(/[^0-9.]/g, ''))\n\n    if (Number.isNaN(value)) {\n      throw new Error(\n        `priceValue() could not read a price from \"${subject.text()}\"`\n      )\n    }\n\n    return value\n  }\n})\nexport {}\n```\n\ncypress/support/commands.ts\n\n```\ndeclare global {\n  namespace Cypress {\n    interface Chainable {\n      priceValue(): Chainable<number>\n    }\n  }\n}\n\nCypress.Commands.addQuery('priceValue', function () {\n  return (subject) => {\n    Cypress.ensure.isElement(subject, 'priceValue', cy)\n\n    const value = parseFloat(subject.text().replace(/[^0-9.]/g, ''))\n\n    if (Number.isNaN(value)) {\n      throw new Error(\n        `priceValue() could not read a price from \"${subject.text()}\"`\n      )\n    }\n\n    return value\n  }\n})\n\nexport {}\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 2471
    },
    {
      "id": "api/cypress-api/ensure#compare-a-hand-written-error-with-an-ensure-error",
      "doc_id": "api/cypress-api/ensure",
      "heading": "Compare a hand-written error with an ensure error",
      "heading_level": 3,
      "content_markdown": "### Compare a hand-written error with an ensure error\n\nBoth versions of the `.inputValue()` query below reject a subject that isn't an element. The first throws its own error:\n\n*   JavaScript\n*   TypeScript\n\ncypress/support/commands.js\n\n```\nCypress.Commands.addQuery('inputValue', function () {\n  return (subject) => {\n    if (!Cypress.dom.isElement(subject)) {\n      throw new Error('inputValue() requires an element')\n    }\n\n    return subject.val()\n  }\n})\nexport {}\n```\n\ncypress/support/commands.ts\n\n```\ndeclare global {\n  namespace Cypress {\n    interface Chainable {\n      inputValue(): Chainable<string | number | string[] | undefined>\n    }\n  }\n}\n\nCypress.Commands.addQuery('inputValue', function () {\n  return (subject) => {\n    if (!Cypress.dom.isElement(subject)) {\n      throw new Error('inputValue() requires an element')\n    }\n\n    return subject.val()\n  }\n})\n\nexport {}\n```\n\nThe second calls `Cypress.ensure.isElement()` instead:\n\n*   JavaScript\n*   TypeScript\n\ncypress/support/commands.js\n\n```\nCypress.Commands.addQuery('inputValue', function () {\n  return (subject) => {\n    Cypress.ensure.isElement(subject, 'inputValue', cy)\n\n    return subject.val()\n  }\n})\nexport {}\n```\n\ncypress/support/commands.ts\n\n```\ndeclare global {\n  namespace Cypress {\n    interface Chainable {\n      inputValue(): Chainable<string | number | string[] | undefined>\n    }\n  }\n}\n\nCypress.Commands.addQuery('inputValue', function () {\n  return (subject) => {\n    Cypress.ensure.isElement(subject, 'inputValue', cy)\n\n    return subject.val()\n  }\n})\n\nexport {}\n```\n\nChain either one off a subject that isn't an element:\n\ncypress/e2e/profile.cy.js\n\n```\ncy.title().inputValue()\n```\n\nThe hand-written check fails with only its own message:\n\n```\nError: Timed out retrying after 4000ms: inputValue() requires an element\n```\n\nThe `ensure` check fails with a Cypress error that names the command, shows the subject it received, and names the command that produced it:\n\n```\nCypressError: Timed out retrying after 4000ms: `cy.inputValue()` failed because it requires a DOM element.\n\nThe subject received was:\n\n  > `Example page`\n\nThe previous command that ran was:\n\n  > `cy.title()`\n```\n",
      "section": "api",
      "anchors": [
        "compare-a-hand-written-error-with-an-ensure-error"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 355
    },
    {
      "id": "api/cypress-api/ensure#choose-between-an-ensure-check-and-an-assertion",
      "doc_id": "api/cypress-api/ensure",
      "heading": "Choose between an ensure check and an assertion",
      "heading_level": 3,
      "content_markdown": "### Choose between an ensure check and an assertion\n\n`Cypress.ensure` and assertions can check the same state, but they belong in different places. In a test, assert the state you expect with [`.should()`](/llm/markdown/api/commands/should.md). Inside a custom query or command, call `Cypress.ensure`, so every test that uses the query gets the check, and the error names the query:\n\ncypress/e2e/profile.cy.js\n\n```\n// In a test: assert the state you expect\ncy.get('#email').should('be.enabled')\n\n// In a custom query: the check is part of the query\ncy.get('#email').editable()\n```\n\n`.editable()` is defined in [Wait for an element to be editable in a custom query](#Wait-for-an-element-to-be-editable-in-a-custom-query).\n",
      "section": "api",
      "anchors": [
        "choose-between-an-ensure-check-and-an-assertion"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 131
    },
    {
      "id": "api/cypress-api/ensure#accept-only-certain-subject-types-in-a-custom-query",
      "doc_id": "api/cypress-api/ensure",
      "heading": "Accept only certain subject types in a custom query",
      "heading_level": 3,
      "content_markdown": "### Accept only certain subject types in a custom query\n\nThe `.dataCy()` query below finds elements by their `data-cy` attribute. It can start a chain, where it searches the whole page, or continue one, where it searches inside the previous element or document. `isType()` rejects every other subject, such as a string yielded by [`.invoke()`](/llm/markdown/api/commands/invoke.md).\n\n*   JavaScript\n*   TypeScript\n\ncypress/support/commands.js\n\n```\nCypress.Commands.addQuery('dataCy', function (value) {\n  return (subject) => {\n    Cypress.ensure.isType(\n      subject,\n      ['optional', 'element', 'document'],\n      'dataCy',\n      cy\n    )\n\n    const $root = subject === undefined ? cy.$$('body') : Cypress.$(subject)\n\n    return $root.find(`[data-cy=\"${value}\"]`)\n  }\n})\nexport {}\n```\n\ncypress/support/commands.ts\n\n```\ndeclare global {\n  namespace Cypress {\n    interface Chainable {\n      dataCy(value: string): Chainable<JQuery<HTMLElement>>\n    }\n  }\n}\n\nCypress.Commands.addQuery('dataCy', function (value: string) {\n  return (subject) => {\n    Cypress.ensure.isType(\n      subject,\n      ['optional', 'element', 'document'],\n      'dataCy',\n      cy\n    )\n\n    const $root = subject === undefined ? cy.$$('body') : Cypress.$(subject)\n\n    return $root.find(`[data-cy=\"${value}\"]`)\n  }\n})\n\nexport {}\n```\n\nThen use it at the start of a chain or after another query:\n\ncypress/e2e/data-cy.cy.js\n\n```\ncy.dataCy('submit').should('have.text', 'Submit')\ncy.get('form').dataCy('email').should('have.attr', 'type', 'email')\n```\n\nChaining `.dataCy()` off a subject it doesn't accept fails with a Cypress error that lists every accepted type:\n\ncypress/e2e/data-cy.cy.js\n\n```\ncy.title().dataCy('submit')\n```\n\n```\nCypressError: Timed out retrying after 4000ms: `cy.dataCy()` failed because it requires a DOM element or document.\n\nThe subject received was:\n\n  > `Example page`\n\nThe previous command that ran was:\n\n  > `cy.title()`\n```\n",
      "section": "api",
      "anchors": [
        "accept-only-certain-subject-types-in-a-custom-query"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 295
    },
    {
      "id": "api/cypress-api/ensure#wait-for-an-element-to-be-editable-in-a-custom-query",
      "doc_id": "api/cypress-api/ensure",
      "heading": "Wait for an element to be editable in a custom query",
      "heading_level": 3,
      "content_markdown": "### Wait for an element to be editable in a custom query\n\nCypress retries the checks inside a custom query, so a query built from `Cypress.ensure` functions waits for the element to reach the state you need. The `.editable()` query yields its subject once it is visible, enabled, and not read-only, and fails with Cypress's own actionability error if it never gets there.\n\n*   JavaScript\n*   TypeScript\n\ncypress/support/commands.js\n\n```\nCypress.Commands.addQuery('editable', function () {\n  return (subject) => {\n    Cypress.ensure.isElement(subject, 'editable', cy)\n    Cypress.ensure.isVisible(subject, 'editable')\n    Cypress.ensure.isNotDisabled(subject, 'editable')\n    Cypress.ensure.isNotReadonly(subject, 'editable')\n\n    return subject\n  }\n})\nexport {}\n```\n\ncypress/support/commands.ts\n\n```\ndeclare global {\n  namespace Cypress {\n    interface Chainable {\n      editable(): Chainable<JQuery<HTMLElement>>\n    }\n  }\n}\n\nCypress.Commands.addQuery('editable', function () {\n  return (subject) => {\n    Cypress.ensure.isElement(subject, 'editable', cy)\n    Cypress.ensure.isVisible(subject, 'editable')\n    Cypress.ensure.isNotDisabled(subject, 'editable')\n    Cypress.ensure.isNotReadonly(subject, 'editable')\n\n    return subject\n  }\n})\n\nexport {}\n```\n\nHere, the `#email` input starts out disabled and the app enables it after it loads the user's profile. `.editable()` retries until the input is enabled, then [`.invoke()`](/llm/markdown/api/commands/invoke.md) sets its value:\n\ncypress/e2e/profile.cy.js\n\n```\ncy.get('#email').editable().invoke('val', 'jane@example.com')\ncy.get('#email').should('have.value', 'jane@example.com')\n```\n\nIf the input stays disabled, the query times out with the same error a [`.type()`](/llm/markdown/api/commands/type.md) into a disabled input produces:\n\n```\nCypressError: Timed out retrying after 4000ms: `cy.editable()` failed because this element is `disabled`:\n\n`<input id=\"email\" type=\"email\" disabled=\"\">`\n\nFix this problem, or use `{force: true}` to disable error checking.\n\nhttps://on.cypress.io/element-cannot-be-interacted-with\n```\n\nIn the Cypress App, the error appears under the failed test and names `cy.editable()`, the same way it names a built-in command:\n",
      "section": "api",
      "anchors": [
        "wait-for-an-element-to-be-editable-in-a-custom-query"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 324
    },
    {
      "id": "api/cypress-api/ensure#support-a-force-option-in-a-custom-query",
      "doc_id": "api/cypress-api/ensure",
      "heading": "Support a force option in a custom query",
      "heading_level": 3,
      "content_markdown": "### Support a force option in a custom query\n\nSome `ensure` errors end with `use {force: true} to disable error checking`, a hint written for built-in commands such as [`.type()`](/llm/markdown/api/commands/type.md). To make that hint true for your own query, accept a `force` option and skip the state checks when it's set. This version of `.editable()` keeps the type check either way:\n\n*   JavaScript\n*   TypeScript\n\ncypress/support/commands.js\n\n```\nCypress.Commands.addQuery('editable', function (options = {}) {\n  return (subject) => {\n    Cypress.ensure.isElement(subject, 'editable', cy)\n\n    if (!options.force) {\n      Cypress.ensure.isVisible(subject, 'editable')\n      Cypress.ensure.isNotDisabled(subject, 'editable')\n      Cypress.ensure.isNotReadonly(subject, 'editable')\n    }\n\n    return subject\n  }\n})\nexport {}\n```\n\ncypress/support/commands.ts\n\n```\ndeclare global {\n  namespace Cypress {\n    interface Chainable {\n      editable(options?: { force?: boolean }): Chainable<JQuery<HTMLElement>>\n    }\n  }\n}\n\nCypress.Commands.addQuery(\n  'editable',\n  function (options: { force?: boolean } = {}) {\n    return (subject) => {\n      Cypress.ensure.isElement(subject, 'editable', cy)\n\n      if (!options.force) {\n        Cypress.ensure.isVisible(subject, 'editable')\n        Cypress.ensure.isNotDisabled(subject, 'editable')\n        Cypress.ensure.isNotReadonly(subject, 'editable')\n      }\n\n      return subject\n    }\n  }\n)\n\nexport {}\n```\n\nWith `{ force: true }`, the query yields the disabled `#locked` input right away, and `.invoke()` sets its value:\n\ncypress/e2e/profile.cy.js\n\n```\ncy.get('#locked').editable({ force: true }).invoke('val', 'jane@example.com')\n```\n",
      "section": "api",
      "anchors": [
        "support-a-force-option-in-a-custom-query"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 240
    },
    {
      "id": "api/cypress-api/ensure#wait-for-a-carousel-slide-to-scroll-into-view",
      "doc_id": "api/cypress-api/ensure",
      "heading": "Wait for a carousel slide to scroll into view",
      "heading_level": 3,
      "content_markdown": "### Wait for a carousel slide to scroll into view\n\nAn element scrolled outside an `overflow: hidden` container is still in the page, but the reader can't see it. The `.unclipped()` query retries until no ancestor clips its subject:\n\n*   JavaScript\n*   TypeScript\n\ncypress/support/commands.js\n\n```\nCypress.Commands.addQuery('unclipped', function () {\n  return (subject) => {\n    Cypress.ensure.isElement(subject, 'unclipped', cy)\n    Cypress.ensure.isNotHiddenByAncestors(subject, 'unclipped')\n\n    return subject\n  }\n})\nexport {}\n```\n\ncypress/support/commands.ts\n\n```\ndeclare global {\n  namespace Cypress {\n    interface Chainable {\n      unclipped(): Chainable<JQuery<HTMLElement>>\n    }\n  }\n}\n\nCypress.Commands.addQuery('unclipped', function () {\n  return (subject) => {\n    Cypress.ensure.isElement(subject, 'unclipped', cy)\n    Cypress.ensure.isNotHiddenByAncestors(subject, 'unclipped')\n\n    return subject\n  }\n})\n\nexport {}\n```\n\nHere, clicking `\"Next\"` scrolls the carousel to the second slide. `.unclipped()` waits for the scroll to finish before the assertion runs:\n\ncypress/e2e/carousel.cy.js\n\n```\ncy.get('#next').click()\ncy.contains('.slide', 'Slide 2').unclipped().should('have.text', 'Slide 2')\n```\n",
      "section": "api",
      "anchors": [
        "wait-for-a-carousel-slide-to-scroll-into-view"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 175
    },
    {
      "id": "api/cypress-api/ensure#read-a-documents-meta-tags-in-a-custom-query",
      "doc_id": "api/cypress-api/ensure",
      "heading": "Read a document's meta tags in a custom query",
      "heading_level": 3,
      "content_markdown": "### Read a document's meta tags in a custom query\n\nThe `.metaContent()` query reads a `<meta>` tag from the [`cy.document()`](/llm/markdown/api/commands/document.md) subject, and `isDocument()` rejects any other subject. Because it's a query, an assertion on its value retries until the app updates the tag:\n\n*   JavaScript\n*   TypeScript\n\ncypress/support/commands.js\n\n```\nCypress.Commands.addQuery('metaContent', function (name) {\n  return (subject) => {\n    Cypress.ensure.isDocument(subject, 'metaContent', cy)\n\n    return subject\n      .querySelector(`meta[name=\"${name}\"]`)\n      ?.getAttribute('content')\n  }\n})\nexport {}\n```\n\ncypress/support/commands.ts\n\n```\ndeclare global {\n  namespace Cypress {\n    interface Chainable {\n      metaContent(name: string): Chainable<string | null | undefined>\n    }\n  }\n}\n\nCypress.Commands.addQuery('metaContent', function (name: string) {\n  return (subject) => {\n    Cypress.ensure.isDocument(subject, 'metaContent', cy)\n\n    return subject\n      .querySelector(`meta[name=\"${name}\"]`)\n      ?.getAttribute('content')\n  }\n})\n\nexport {}\n```\n\ncypress/e2e/seo.cy.js\n\n```\ncy.document().metaContent('description').should('eq', 'Cypress example app')\n```\n",
      "section": "api",
      "anchors": [
        "read-a-documents-meta-tags-in-a-custom-query"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 157
    },
    {
      "id": "api/cypress-api/ensure#read-the-apps-localstorage-keys-in-a-custom-query",
      "doc_id": "api/cypress-api/ensure",
      "heading": "Read the app's localStorage keys in a custom query",
      "heading_level": 3,
      "content_markdown": "### Read the app's localStorage keys in a custom query\n\nThe `.storageKeys()` query reads the keys in the app's `localStorage` from the [`cy.window()`](/llm/markdown/api/commands/window.md) subject, and retries until an assertion on them passes:\n\n*   JavaScript\n*   TypeScript\n\ncypress/support/commands.js\n\n```\nCypress.Commands.addQuery('storageKeys', function () {\n  return (subject) => {\n    Cypress.ensure.isWindow(subject, 'storageKeys', cy)\n\n    return Object.keys(subject.localStorage)\n  }\n})\nexport {}\n```\n\ncypress/support/commands.ts\n\n```\ndeclare global {\n  namespace Cypress {\n    interface Chainable {\n      storageKeys(): Chainable<string[]>\n    }\n  }\n}\n\nCypress.Commands.addQuery('storageKeys', function () {\n  return (subject) => {\n    Cypress.ensure.isWindow(subject, 'storageKeys', cy)\n\n    return Object.keys(subject.localStorage)\n  }\n})\n\nexport {}\n```\n\ncypress/e2e/auth.cy.js\n\n```\ncy.window().storageKeys().should('include', 'authToken')\n```\n",
      "section": "api",
      "anchors": [
        "read-the-apps-localstorage-keys-in-a-custom-query"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 127
    },
    {
      "id": "api/cypress-api/ensure#check-an-element-before-acting-on-it-in-a-custom-command",
      "doc_id": "api/cypress-api/ensure",
      "heading": "Check an element before acting on it in a custom command",
      "heading_level": 3,
      "content_markdown": "### Check an element before acting on it in a custom command\n\nA custom command added with [`Cypress.Commands.add()`](/llm/markdown/api/cypress-api/custom-commands.md) runs once and is not retried, so a failed check fails the test right away. The `.scrollToBottom()` command below checks that its subject can be scrolled before it changes the element's `scrollTop`, then yields the element so the chain can continue.\n\n*   JavaScript\n*   TypeScript\n\ncypress/support/commands.js\n\n```\nCypress.Commands.add(\n  'scrollToBottom',\n  { prevSubject: 'element' },\n  (subject) => {\n    Cypress.ensure.isScrollable(subject, 'scrollToBottom')\n\n    subject[0].scrollTop = subject[0].scrollHeight\n\n    return cy.wrap(subject, { log: false })\n  }\n)\nexport {}\n```\n\ncypress/support/commands.ts\n\n```\ndeclare global {\n  namespace Cypress {\n    interface Chainable {\n      scrollToBottom(): Chainable<JQuery<HTMLElement>>\n    }\n  }\n}\n\nCypress.Commands.add(\n  'scrollToBottom',\n  { prevSubject: 'element' },\n  (subject) => {\n    Cypress.ensure.isScrollable(subject, 'scrollToBottom')\n\n    subject[0].scrollTop = subject[0].scrollHeight\n\n    return cy.wrap(subject, { log: false })\n  }\n)\n\nexport {}\n```\n\ncypress/e2e/messages.cy.js\n\n```\ncy.get('#messages')\n  .scrollToBottom()\n  .contains('Latest message')\n  .should('be.visible')\n```\n\nCalling it on an element that can't scroll fails with:\n\n```\nCypressError: `cy.scrollToBottom()` failed because this element is not scrollable:\n\n`<div id=\"footer\">Footer</div>`\n\nMake sure you're targeting the correct element or use `{ensureScrollable: false}` to disable the scrollable check.\n\nhttps://on.cypress.io/scrollto\n```\n\nThe message ends with the hint and docs link Cypress shows for its own [`.scrollTo()`](/llm/markdown/api/commands/scrollto.md) command. See [Error messages come from the built-in commands](#Error-messages-come-from-the-built-in-commands).\n",
      "section": "api",
      "anchors": [
        "check-an-element-before-acting-on-it-in-a-custom-command"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 271
    },
    {
      "id": "api/cypress-api/ensure#guard-a-native-dom-call-against-a-detached-element",
      "doc_id": "api/cypress-api/ensure",
      "heading": "Guard a native DOM call against a detached element",
      "heading_level": 3,
      "content_markdown": "### Guard a native DOM call against a detached element\n\nThe `.saveAndCollapse()` command clicks a panel's `\"Save\"` button, then clicks its `\"Collapse\"` button with a native DOM `click()`. Saving can re-render the panel, which leaves `subject` pointing at a detached element, and a native click on it never reaches the panel on the page. `isAttached()` turns that silent miss into a clear failure:\n\n*   JavaScript\n*   TypeScript\n\ncypress/support/commands.js\n\n```\nCypress.Commands.add(\n  'saveAndCollapse',\n  { prevSubject: 'element' },\n  (subject) => {\n    cy.wrap(subject).contains('button', 'Save').click()\n\n    cy.then(() => {\n      // Saving can re-render the panel and detach `subject`\n      Cypress.ensure.isAttached(subject, 'saveAndCollapse', cy)\n\n      subject.find('[data-cy=\"collapse\"]')[0].click()\n    })\n  }\n)\nexport {}\n```\n\ncypress/support/commands.ts\n\n```\ndeclare global {\n  namespace Cypress {\n    interface Chainable {\n      saveAndCollapse(): Chainable<void>\n    }\n  }\n}\n\nCypress.Commands.add(\n  'saveAndCollapse',\n  { prevSubject: 'element' },\n  (subject) => {\n    cy.wrap(subject).contains('button', 'Save').click()\n\n    cy.then(() => {\n      // Saving can re-render the panel and detach `subject`\n      Cypress.ensure.isAttached(subject, 'saveAndCollapse', cy)\n\n      subject.find('[data-cy=\"collapse\"]')[0].click()\n    })\n  }\n)\n\nexport {}\n```\n\ncypress/e2e/settings.cy.js\n\n```\ncy.get('#panel').saveAndCollapse()\n```\n",
      "section": "api",
      "anchors": [
        "guard-a-native-dom-call-against-a-detached-element"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 207
    },
    {
      "id": "api/cypress-api/ensure#write-your-own-subject-check-in-a-custom-query",
      "doc_id": "api/cypress-api/ensure",
      "heading": "Write your own subject check in a custom query",
      "heading_level": 3,
      "content_markdown": "### Write your own subject check in a custom query\n\n`Cypress.ensure` covers the subject checks Cypress itself needs. For any other condition, throw an error from your query's inner function. Cypress retries it the same way it retries an `ensure` check:\n\n*   JavaScript\n*   TypeScript\n\ncypress/support/commands.js\n\n```\nCypress.Commands.addQuery('priceValue', function () {\n  return (subject) => {\n    Cypress.ensure.isElement(subject, 'priceValue', cy)\n\n    const value = parseFloat(subject.text().replace(/[^0-9.]/g, ''))\n\n    if (Number.isNaN(value)) {\n      throw new Error(\n        `priceValue() could not read a price from \"${subject.text()}\"`\n      )\n    }\n\n    return value\n  }\n})\nexport {}\n```\n\ncypress/support/commands.ts\n\n```\ndeclare global {\n  namespace Cypress {\n    interface Chainable {\n      priceValue(): Chainable<number>\n    }\n  }\n}\n\nCypress.Commands.addQuery('priceValue', function () {\n  return (subject) => {\n    Cypress.ensure.isElement(subject, 'priceValue', cy)\n\n    const value = parseFloat(subject.text().replace(/[^0-9.]/g, ''))\n\n    if (Number.isNaN(value)) {\n      throw new Error(\n        `priceValue() could not read a price from \"${subject.text()}\"`\n      )\n    }\n\n    return value\n  }\n})\n\nexport {}\n```\n",
      "section": "api",
      "anchors": [
        "write-your-own-subject-check-in-a-custom-query"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 188
    },
    {
      "id": "api/cypress-api/ensure#notes",
      "doc_id": "api/cypress-api/ensure",
      "heading": "Notes",
      "heading_level": 2,
      "content_markdown": "## Notes\n\n### Retry behavior of ensure checks in queries and commands\n\n`Cypress.ensure` functions throw an error and nothing more. What happens next depends on where you call them:\n\n*   In the inner function of a [custom query](/llm/markdown/api/cypress-api/custom-queries.md), Cypress retries the function until it stops throwing or the query times out, then fails the test with the last error, prefixed with `Timed out retrying after…`.\n*   In a [custom command](/llm/markdown/api/cypress-api/custom-commands.md) or a [`.then()`](/llm/markdown/api/commands/then.md) callback, the error fails the test right away.\n\nCall them while a command is running, from a query, a command, or a callback. The type checks read the running command from `cy` to build their error message.\n\n### Error messages come from the built-in commands\n\nEach check throws the error message Cypress uses for its own commands, with your `commandName` in place of the built-in name. Some messages end with a hint written for those commands, such as `use {force: true} to disable error checking`. Your query or command only supports that option if you add it, as in [Support a force option in a custom query](#Support-a-force-option-in-a-custom-query). Otherwise, when the hint would mislead your readers, write your own check instead.\n",
      "section": "api",
      "anchors": [
        "notes"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 257
    },
    {
      "id": "api/cypress-api/ensure#retry-behavior-of-ensure-checks-in-queries-and-commands",
      "doc_id": "api/cypress-api/ensure",
      "heading": "Retry behavior of ensure checks in queries and commands",
      "heading_level": 3,
      "content_markdown": "### Retry behavior of ensure checks in queries and commands\n\n`Cypress.ensure` functions throw an error and nothing more. What happens next depends on where you call them:\n\n*   In the inner function of a [custom query](/llm/markdown/api/cypress-api/custom-queries.md), Cypress retries the function until it stops throwing or the query times out, then fails the test with the last error, prefixed with `Timed out retrying after…`.\n*   In a [custom command](/llm/markdown/api/cypress-api/custom-commands.md) or a [`.then()`](/llm/markdown/api/commands/then.md) callback, the error fails the test right away.\n\nCall them while a command is running, from a query, a command, or a callback. The type checks read the running command from `cy` to build their error message.\n",
      "section": "api",
      "anchors": [
        "retry-behavior-of-ensure-checks-in-queries-and-commands"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 144
    },
    {
      "id": "api/cypress-api/ensure#error-messages-come-from-the-built-in-commands",
      "doc_id": "api/cypress-api/ensure",
      "heading": "Error messages come from the built-in commands",
      "heading_level": 3,
      "content_markdown": "### Error messages come from the built-in commands\n\nEach check throws the error message Cypress uses for its own commands, with your `commandName` in place of the built-in name. Some messages end with a hint written for those commands, such as `use {force: true} to disable error checking`. Your query or command only supports that option if you add it, as in [Support a force option in a custom query](#Support-a-force-option-in-a-custom-query). Otherwise, when the hint would mislead your readers, write your own check instead.\n",
      "section": "api",
      "anchors": [
        "error-messages-come-from-the-built-in-commands"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 111
    },
    {
      "id": "api/cypress-api/ensure#see-also",
      "doc_id": "api/cypress-api/ensure",
      "heading": "See also",
      "heading_level": 2,
      "content_markdown": "## See also\n\n*   [Custom Queries](/llm/markdown/api/cypress-api/custom-queries.md) - the main place to use `Cypress.ensure`\n*   [Custom Commands](/llm/markdown/api/cypress-api/custom-commands.md)\n*   [`Cypress.dom`](/llm/markdown/api/cypress-api/dom.md) - DOM helpers that return a boolean instead of throwing\n*   [Interacting with Elements](/llm/markdown/app/core-concepts/interacting-with-elements.md) - the actionability checks Cypress runs before it acts on an element\n",
      "section": "api",
      "anchors": [
        "see-also"
      ],
      "path": "/llm/json/chunked/api/cypress-api/ensure.json",
      "token_estimate": 59
    }
  ]
}