{
  "doc": {
    "id": "api/utilities/promise",
    "title": "Cypress.Promise | Cypress Documentation",
    "description": "Cypress automatically includes Bluebird and exposes it as Cypress.Promise.",
    "section": "api",
    "source_path": "/llm/markdown/api/utilities/promise.md",
    "version": "e6988a974973e9090ce70406c38cb2b9e0eac9fa",
    "updated_at": "2026-05-15T15:50:22.536Z",
    "headings": [
      {
        "id": "api/utilities/promise#cypress-promise",
        "text": "Cypress.Promise",
        "level": 1
      },
      {
        "id": "api/utilities/promise#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/utilities/promise#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/utilities/promise#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/utilities/promise#basic-promise",
        "text": "Basic Promise",
        "level": 3
      },
      {
        "id": "api/utilities/promise#waiting-for-promises",
        "text": "Waiting for Promises",
        "level": 3
      },
      {
        "id": "api/utilities/promise#notes",
        "text": "Notes",
        "level": 2
      },
      {
        "id": "api/utilities/promise#rejected-test-promises-do-not-fail-tests",
        "text": "Rejected test promises do not fail tests",
        "level": 3
      },
      {
        "id": "api/utilities/promise#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/utilities/promise#syntax",
      "doc_id": "api/utilities/promise",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\nnew Cypress.Promise(fn)\n```\n\n### Usage\n\n**Correct Usage**\n\n```\nnew Cypress.Promise((resolve, reject) => { ... })\n```\n\n**Incorrect Usage**\n\n```\nnew cy.Promise(...)  // Errors, cannot be chained off 'cy'\n```\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/utilities/promise.json",
      "token_estimate": 43
    },
    {
      "id": "api/utilities/promise#examples",
      "doc_id": "api/utilities/promise",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\nUse `Cypress.Promise` to create promises. Cypress is promise aware so if you return a promise from inside of commands like [`.then()`](/llm/markdown/api/commands/then.md), Cypress will not continue until those promises resolve.\n\n### Basic Promise\n\n```\ncy.get('button').then(($button) => {  return new Cypress.Promise((resolve, reject) => {    // do something custom here  })})\n```\n\n### Waiting for Promises\n\n```\nit('waits for promises to resolve', () => {  let waited = false  function waitOneSecond() {    // return a promise that resolves after 1 second    return new Cypress.Promise((resolve, reject) => {      setTimeout(() => {        // set waited to true        waited = true        // resolve with 'foo' string        resolve('foo')      }, 1000)    })  }  cy.wrap(null).then(() => {    // return a promise to cy.then() that    // is awaited until it resolves    return waitOneSecond().then((str) => {      expect(str).to.eq('foo')      expect(waited).to.be.true    })  })})\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/utilities/promise.json",
      "token_estimate": 176
    },
    {
      "id": "api/utilities/promise#waiting-for-promises",
      "doc_id": "api/utilities/promise",
      "heading": "Waiting for Promises",
      "heading_level": 3,
      "content_markdown": "### Waiting for Promises\n\n```\nit('waits for promises to resolve', () => {  let waited = false  function waitOneSecond() {    // return a promise that resolves after 1 second    return new Cypress.Promise((resolve, reject) => {      setTimeout(() => {        // set waited to true        waited = true        // resolve with 'foo' string        resolve('foo')      }, 1000)    })  }  cy.wrap(null).then(() => {    // return a promise to cy.then() that    // is awaited until it resolves    return waitOneSecond().then((str) => {      expect(str).to.eq('foo')      expect(waited).to.be.true    })  })})\n```\n",
      "section": "api",
      "anchors": [
        "waiting-for-promises"
      ],
      "path": "/llm/json/chunked/api/utilities/promise.json",
      "token_estimate": 108
    },
    {
      "id": "api/utilities/promise#notes",
      "doc_id": "api/utilities/promise",
      "heading": "Notes",
      "heading_level": 2,
      "content_markdown": "## Notes\n\n### Rejected test promises do not fail tests\n\nIf the test code has an unhandled rejected promise, it does not automatically fail the test. If you do want to fail the test if there is an unhandled rejected promise in the test code you have to do one of two things:\n\nIf you use `Cypress.Promise` in your test code, register a callback using Bluebird's API\n\n```\nCypress.Promise.onPossiblyUnhandledRejection((error, promise) => {  throw error})\n```\n\nIf you use native built-in promises in your test code, register an event listener on the test `window` object:\n\n```\nwindow.addEventListener('unhandledrejection', (event) => {  throw event.reason})\n```\n\n**Note:** because this is the test `window` object, such listeners are NOT reset before every test. You can register such listeners once using the `before` hook in the spec file.\n",
      "section": "api",
      "anchors": [
        "notes"
      ],
      "path": "/llm/json/chunked/api/utilities/promise.json",
      "token_estimate": 176
    },
    {
      "id": "api/utilities/promise#rejected-test-promises-do-not-fail-tests",
      "doc_id": "api/utilities/promise",
      "heading": "Rejected test promises do not fail tests",
      "heading_level": 3,
      "content_markdown": "### Rejected test promises do not fail tests\n\nIf the test code has an unhandled rejected promise, it does not automatically fail the test. If you do want to fail the test if there is an unhandled rejected promise in the test code you have to do one of two things:\n\nIf you use `Cypress.Promise` in your test code, register a callback using Bluebird's API\n\n```\nCypress.Promise.onPossiblyUnhandledRejection((error, promise) => {  throw error})\n```\n\nIf you use native built-in promises in your test code, register an event listener on the test `window` object:\n\n```\nwindow.addEventListener('unhandledrejection', (event) => {  throw event.reason})\n```\n\n**Note:** because this is the test `window` object, such listeners are NOT reset before every test. You can register such listeners once using the `before` hook in the spec file.\n",
      "section": "api",
      "anchors": [
        "rejected-test-promises-do-not-fail-tests"
      ],
      "path": "/llm/json/chunked/api/utilities/promise.json",
      "token_estimate": 173
    }
  ]
}