{
  "doc": {
    "id": "api/commands/should",
    "title": "should | Cypress Documentation",
    "description": "Create an assertion in Cypress.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/should.md",
    "version": "48b03b5502f7aea1d0454750cce208f775403542",
    "updated_at": "2026-05-20T19:00:20.270Z",
    "headings": [
      {
        "id": "api/commands/should#should",
        "text": "should",
        "level": 1
      },
      {
        "id": "api/commands/should#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/should#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/should#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/should#yields-learn-about-subject-management",
        "text": "Yields Learn about subject management",
        "level": 3
      },
      {
        "id": "api/commands/should#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/should#chainers",
        "text": "Chainers",
        "level": 3
      },
      {
        "id": "api/commands/should#assert-the-checkbox-is-disabled",
        "text": "Assert the checkbox is disabled",
        "level": 4
      },
      {
        "id": "api/commands/should#the-current-dom-element-is-yielded",
        "text": "The current DOM element is yielded",
        "level": 4
      },
      {
        "id": "api/commands/should#value",
        "text": "Value",
        "level": 3
      },
      {
        "id": "api/commands/should#assert-the-class-is-form-horizontal",
        "text": "Assert the class is 'form-horizontal'",
        "level": 4
      },
      {
        "id": "api/commands/should#assert-the-value-is-not-jane",
        "text": "Assert the value is not 'Jane'",
        "level": 4
      },
      {
        "id": "api/commands/should#the-current-subject-is-yielded",
        "text": "The current subject is yielded",
        "level": 4
      },
      {
        "id": "api/commands/should#method-and-value",
        "text": "Method and Value",
        "level": 3
      },
      {
        "id": "api/commands/should#assert-the-anchor-element-has-href-attribute",
        "text": "Assert the anchor element has href attribute",
        "level": 4
      },
      {
        "id": "api/commands/should#assert-the-href-attribute-is-equal-to-users",
        "text": "Assert the href attribute is equal to '/users'",
        "level": 4
      },
      {
        "id": "api/commands/should#focus",
        "text": "Focus",
        "level": 3
      },
      {
        "id": "api/commands/should#assert-an-input-is-focused-after-button-click",
        "text": "Assert an input is focused after button click",
        "level": 4
      },
      {
        "id": "api/commands/should#function",
        "text": "Function",
        "level": 3
      },
      {
        "id": "api/commands/should#verify-length-content-and-classes-from-multiple-p",
        "text": "Verify length, content, and classes from multiple <p>",
        "level": 4
      },
      {
        "id": "api/commands/should#assert-class-name-contains-heading",
        "text": "Assert class name contains heading-",
        "level": 4
      },
      {
        "id": "api/commands/should#assert-text-content-of-3-elements",
        "text": "Assert text content of 3 elements",
        "level": 4
      },
      {
        "id": "api/commands/should#compare-text-values-of-two-elements",
        "text": "Compare text values of two elements",
        "level": 4
      },
      {
        "id": "api/commands/should#multiple-assertions",
        "text": "Multiple Assertions",
        "level": 3
      },
      {
        "id": "api/commands/should#chaining-multiple-assertions",
        "text": "Chaining multiple assertions",
        "level": 4
      },
      {
        "id": "api/commands/should#wait-until-the-assertions-pass",
        "text": "Wait until the assertions pass",
        "level": 3
      },
      {
        "id": "api/commands/should#notes",
        "text": "Notes",
        "level": 2
      },
      {
        "id": "api/commands/should#subjects",
        "text": "Subjects",
        "level": 3
      },
      {
        "id": "api/commands/should#how-do-i-know-which-assertions-change-the-subject-and-which-keep-it-the-same",
        "text": "How do I know which assertions change the subject and which keep it the same?",
        "level": 4
      },
      {
        "id": "api/commands/should#using-a-callback-function-will-not-change-what-is-yielded",
        "text": "Using a callback function will not change what is yielded",
        "level": 4
      },
      {
        "id": "api/commands/should#differences",
        "text": "Differences",
        "level": 3
      },
      {
        "id": "api/commands/should#whats-the-difference-between-then-and-should-and",
        "text": "What's the difference between .then() and .should()/.and()?",
        "level": 3
      },
      {
        "id": "api/commands/should#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/should#requirements-learn-about-chaining-commands",
        "text": "Requirements Learn about chaining commands",
        "level": 3
      },
      {
        "id": "api/commands/should#timeouts-learn-about-timeouts",
        "text": "Timeouts Learn about timeouts",
        "level": 3
      },
      {
        "id": "api/commands/should#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/should#history",
        "text": "History",
        "level": 2
      },
      {
        "id": "api/commands/should#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/commands/should#syntax",
      "doc_id": "api/commands/should",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\n.should(chainers).should(chainers, value).should(chainers, method, value).should(callbackFn)\n```\n\n### Usage\n\n**Correct Usage**\n\n```\ncy.get('.error').should('be.empty') // Assert that '.error' is emptycy.contains('Login').should('be.visible') // Assert that el is visiblecy.wrap({ foo: 'bar' }).its('foo').should('eq', 'bar') // Assert the 'foo' property equals 'bar'\n```\n\n**Incorrect Usage**\n\n```\ncy.should('eq', '42') // Should not be chained off 'cy'\n```\n\n### Arguments\n\n**chainers _(String)_**\n\nAny valid chainer that comes from [Chai](/llm/markdown/app/references/assertions.md#Chai) or [Chai-jQuery](/llm/markdown/app/references/assertions.md#Chai-jQuery) or [Sinon-Chai](/llm/markdown/app/references/assertions.md#Sinon-Chai).\n\n**value _(String)_**\n\nValue to assert against chainer.\n\n**method _(String)_**\n\nA method to be called on the chainer.\n\n**callbackFn _(Function)_**\n\nPass a function that can have any number of explicit assertions within it. Whatever was passed to the function is what is yielded.\n\n### Yields [Learn about subject management](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management)\n\nIn most cases, `.should()` yields the same subject it was given from the previous command.\n\n```\ncy.get('nav') // yields <nav>  .should('be.visible') // yields <nav>\n```\n\nHowever, some chainers change the subject. In the example below, the second `.should()` yields the string `sans-serif` because the chainer `have.css, 'font-family'` changes the subject.\n\n```\ncy.get('nav') // yields <nav>  .should('be.visible') // yields <nav>  .should('have.css', 'font-family') // yields 'sans-serif'  .and('match', /serif/) // yields 'sans-serif'\n```\n\n`.should()` is an assertion, and it is _safe_ to chain further commands that use the subject.\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 267
    },
    {
      "id": "api/commands/should#usage",
      "doc_id": "api/commands/should",
      "heading": "Usage",
      "heading_level": 3,
      "content_markdown": "### Usage\n\n**Correct Usage**\n\n```\ncy.get('.error').should('be.empty') // Assert that '.error' is emptycy.contains('Login').should('be.visible') // Assert that el is visiblecy.wrap({ foo: 'bar' }).its('foo').should('eq', 'bar') // Assert the 'foo' property equals 'bar'\n```\n\n**Incorrect Usage**\n\n```\ncy.should('eq', '42') // Should not be chained off 'cy'\n```\n",
      "section": "api",
      "anchors": [
        "usage"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 57
    },
    {
      "id": "api/commands/should#arguments",
      "doc_id": "api/commands/should",
      "heading": "Arguments",
      "heading_level": 3,
      "content_markdown": "### Arguments\n\n**chainers _(String)_**\n\nAny valid chainer that comes from [Chai](/llm/markdown/app/references/assertions.md#Chai) or [Chai-jQuery](/llm/markdown/app/references/assertions.md#Chai-jQuery) or [Sinon-Chai](/llm/markdown/app/references/assertions.md#Sinon-Chai).\n\n**value _(String)_**\n\nValue to assert against chainer.\n\n**method _(String)_**\n\nA method to be called on the chainer.\n\n**callbackFn _(Function)_**\n\nPass a function that can have any number of explicit assertions within it. Whatever was passed to the function is what is yielded.\n",
      "section": "api",
      "anchors": [
        "arguments"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 76
    },
    {
      "id": "api/commands/should#yields-learn-about-subject-management",
      "doc_id": "api/commands/should",
      "heading": "Yields Learn about subject management",
      "heading_level": 3,
      "content_markdown": "### Yields [Learn about subject management](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management)\n\nIn most cases, `.should()` yields the same subject it was given from the previous command.\n\n```\ncy.get('nav') // yields <nav>  .should('be.visible') // yields <nav>\n```\n\nHowever, some chainers change the subject. In the example below, the second `.should()` yields the string `sans-serif` because the chainer `have.css, 'font-family'` changes the subject.\n\n```\ncy.get('nav') // yields <nav>  .should('be.visible') // yields <nav>  .should('have.css', 'font-family') // yields 'sans-serif'  .and('match', /serif/) // yields 'sans-serif'\n```\n\n`.should()` is an assertion, and it is _safe_ to chain further commands that use the subject.\n",
      "section": "api",
      "anchors": [
        "yields-learn-about-subject-management"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 123
    },
    {
      "id": "api/commands/should#examples",
      "doc_id": "api/commands/should",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\n### Chainers\n\n#### Assert the checkbox is disabled\n\n```\ncy.get(':checkbox').should('be.disabled')\n```\n\n#### The current DOM element is yielded\n\n```\ncy.get('option:first')  .should('be.selected')  .then(($option) => {    // $option is yielded  })\n```\n\n### Value\n\n#### Assert the class is 'form-horizontal'\n\n```\ncy.get('form').should('have.class', 'form-horizontal')\n```\n\n#### Assert the value is not 'Jane'\n\n```\ncy.get('input').should('not.have.value', 'Jane')\n```\n\n#### The current subject is yielded\n\n```\ncy.get('button')  .should('have.id', 'new-user')  .then(($button) => {    // $button is yielded  })\n```\n\n### Method and Value\n\n#### Assert the anchor element has href attribute\n\n```\n// have.attr comes from chai-jquerycy.get('#header a').should('have.attr', 'href')\n```\n\n#### Assert the href attribute is equal to '/users'\n\n```\ncy.get('#header a').should('have.attr', 'href', '/users')\n```\n\n**Note:** the `have.attr` assertion changes the subject from the original element to the attribute's value\n\n```\ncy.get('#header a') // yields the element  .should('have.attr', 'href') // yields the \"href\" attribute  .and('equal', '/users') // checks the \"href\" value\n```\n\n### Focus\n\n#### Assert an input is focused after button click\n\n```\ncy.get('#btn-focuses-input').click()cy.get('#input-receives-focus').should('have.focus') // equivalent to should('be.focused')\n```\n\n### Function\n\nPassing a function to `.should()` enables you to make multiple assertions on the yielded subject. This also gives you the opportunity to _massage_ what you'd like to assert on.\n\nBe sure _not_ to include any code that has side effects in your callback function. The callback function will be retried over and over again until no assertions within it throw.\n\nYou cannot invoke Cypress commands inside of a `.should()` callback function. Use Cypress commands before or after `.should()` instead.\n\n**Incorrect Usage**\n\n```\ncy.get('p').should(($p) => {  cy.log($p)  // ...})\n```\n\n**Correct Usage**\n\n```\ncy.get('p')  .should(($p) => {    // ...  })  .log()// orcy.get('p').then(($p) => {  // ...  cy.log($p)})\n```\n\n#### Verify length, content, and classes from multiple `<p>`\n\n```\n<div>  <p class=\"text-primary\">Hello World</p>  <p class=\"text-danger\">You have an error</p>  <p class=\"text-default\">Try again later</p></div>\n```\n\n```\ncy.get('p').should(($p) => {  // should have found 3 elements  expect($p).to.have.length(3)  // make sure the first contains some text content  expect($p.first()).to.contain('Hello World')  // use jquery's map to grab all of their classes  // jquery's map returns a new jquery object  const classes = $p.map((i, el) => {    return Cypress.$(el).attr('class')  })  // call classes.get() to make this a plain array  expect(classes.get()).to.deep.eq([    'text-primary',    'text-danger',    'text-default',  ])})\n```\n\n**Warning** Any value returned from a `.should()` callback function will be ignored. The original subject will be yielded to the next command.\n\n```\ncy.get('p')  .should(($p) => {    expect($p).to.have.length(3)    return 'foo'  })  .then(($p) => {    // the argument $p will be the 3 elements, not \"foo\"  })\n```\n\n#### Assert class name contains `heading-`\n\n```\n<div class=\"docs-header\">  <div class=\"main-abc123 heading-xyz987\">Introduction</div></div>\n```\n\n```\ncy.get('.docs-header')  .find('div')  // .should(cb) callback function will be retried  .should(($div) => {    expect($div).to.have.length(1)    const className = $div[0].className    expect(className).to.match(/heading-/)  })  // .then(cb) callback is not retried,  // it either passes or fails  .then(($div) => {    expect($div).to.have.text('Introduction')  })\n```\n\nYou can even throw your own errors from the callback function.\n\n```\ncy.get('.docs-header')  .find('div')  .should(($div) => {    if ($div.length !== 1) {      // you can throw your own errors      throw new Error('Did not find 1 element')    }    const className = $div[0].className    if (!className.match(/heading-/)) {      throw new Error(`No class \"heading-\" in ${className}`)    }  })\n```\n\n#### Assert text content of 3 elements\n\nExample below first asserts that there are 3 elements, and then checks the text content of each one.\n\n```\n<ul class=\"connectors-list\">  <li>Walk the dog</li>  <li>Feed the cat</li>  <li>Write JavaScript</li></ul>\n```\n\n```\ncy.get('.connectors-list > li').should(($lis) => {  expect($lis).to.have.length(3)  expect($lis.eq(0)).to.contain('Walk the dog')  expect($lis.eq(1)).to.contain('Feed the cat')  expect($lis.eq(2)).to.contain('Write JavaScript')})\n```\n\nFor clarity you can pass a string message as a second argument to any `expect` assertion, see [Chai#expect](https://www.chaijs.com/guide/styles/#expect).\n\n```\ncy.get('.connectors-list > li').should(($lis) => {  expect($lis, '3 items').to.have.length(3)  expect($lis.eq(0), 'first item').to.contain('Walk the dog')  expect($lis.eq(1), 'second item').to.contain('Feed the cat')  expect($lis.eq(2), 'third item').to.contain('Write JavaScript')})\n```\n\nThese string messages will be shown in the Command Log giving each assertion more context.\n\n#### Compare text values of two elements\n\nThe example below gets the text contained within one element and saves it in a closure variable. Then the test gets the text in another element and asserts that the two text values are the same after normalizing.\n\n```\n<div class=\"company-details\">  <div class=\"title\">Acme Developers</div>  <div class=\"identifier\">ACMEDEVELOPERS</div></div>\n```\n\n```\nconst normalizeText = (s) => s.replace(/\\s/g, '').toLowerCase()// will keep text from title elementlet titleTextcy.get('.company-details')  .find('.title')  .then(($title) => {    // save text from the first element    titleText = normalizeText($title.text())  })cy.get('.company-details')  .find('.identifier')  .should(($identifier) => {    // we can massage text before comparing    const idText = normalizeText($identifier.text())    // text from the title element should already be set    expect(idText, 'ID').to.equal(titleText)  })\n```\n\n### Multiple Assertions\n\n#### Chaining multiple assertions\n\nCypress makes it easier to chain assertions together.\n\nIn this example we use [`.and()`](/llm/markdown/api/commands/and.md) which is identical to `.should()`.\n\n```\n// our subject is not changed by our first assertion,// so we can continue to use DOM based assertionscy.get('option:first').should('be.selected').and('have.value', 'Metallica')\n```\n\n### Wait until the assertions pass\n\nCypress won't resolve your commands until all of its assertions pass.\n\n```\n// Application Code$('button').click(function () {  $button = $(this)  setTimeout(() => {    $button.removeClass('inactive').addClass('active')  }, 1000)})\n```\n\n```\ncy.get('button')  .click()  .should('have.class', 'active')  .and('not.have.class', 'inactive')\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 1103
    },
    {
      "id": "api/commands/should#chainers",
      "doc_id": "api/commands/should",
      "heading": "Chainers",
      "heading_level": 3,
      "content_markdown": "### Chainers\n\n#### Assert the checkbox is disabled\n\n```\ncy.get(':checkbox').should('be.disabled')\n```\n\n#### The current DOM element is yielded\n\n```\ncy.get('option:first')  .should('be.selected')  .then(($option) => {    // $option is yielded  })\n```\n",
      "section": "api",
      "anchors": [
        "chainers"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 40
    },
    {
      "id": "api/commands/should#value",
      "doc_id": "api/commands/should",
      "heading": "Value",
      "heading_level": 3,
      "content_markdown": "### Value\n\n#### Assert the class is 'form-horizontal'\n\n```\ncy.get('form').should('have.class', 'form-horizontal')\n```\n\n#### Assert the value is not 'Jane'\n\n```\ncy.get('input').should('not.have.value', 'Jane')\n```\n\n#### The current subject is yielded\n\n```\ncy.get('button')  .should('have.id', 'new-user')  .then(($button) => {    // $button is yielded  })\n```\n",
      "section": "api",
      "anchors": [
        "value"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 56
    },
    {
      "id": "api/commands/should#method-and-value",
      "doc_id": "api/commands/should",
      "heading": "Method and Value",
      "heading_level": 3,
      "content_markdown": "### Method and Value\n\n#### Assert the anchor element has href attribute\n\n```\n// have.attr comes from chai-jquerycy.get('#header a').should('have.attr', 'href')\n```\n\n#### Assert the href attribute is equal to '/users'\n\n```\ncy.get('#header a').should('have.attr', 'href', '/users')\n```\n\n**Note:** the `have.attr` assertion changes the subject from the original element to the attribute's value\n\n```\ncy.get('#header a') // yields the element  .should('have.attr', 'href') // yields the \"href\" attribute  .and('equal', '/users') // checks the \"href\" value\n```\n",
      "section": "api",
      "anchors": [
        "method-and-value"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 97
    },
    {
      "id": "api/commands/should#assert-the-href-attribute-is-equal-to-users",
      "doc_id": "api/commands/should",
      "heading": "Assert the href attribute is equal to '/users'",
      "heading_level": 4,
      "content_markdown": "#### Assert the href attribute is equal to '/users'\n\n```\ncy.get('#header a').should('have.attr', 'href', '/users')\n```\n\n**Note:** the `have.attr` assertion changes the subject from the original element to the attribute's value\n\n```\ncy.get('#header a') // yields the element  .should('have.attr', 'href') // yields the \"href\" attribute  .and('equal', '/users') // checks the \"href\" value\n```\n",
      "section": "api",
      "anchors": [
        "assert-the-href-attribute-is-equal-to-users"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 69
    },
    {
      "id": "api/commands/should#function",
      "doc_id": "api/commands/should",
      "heading": "Function",
      "heading_level": 3,
      "content_markdown": "### Function\n\nPassing a function to `.should()` enables you to make multiple assertions on the yielded subject. This also gives you the opportunity to _massage_ what you'd like to assert on.\n\nBe sure _not_ to include any code that has side effects in your callback function. The callback function will be retried over and over again until no assertions within it throw.\n\nYou cannot invoke Cypress commands inside of a `.should()` callback function. Use Cypress commands before or after `.should()` instead.\n\n**Incorrect Usage**\n\n```\ncy.get('p').should(($p) => {  cy.log($p)  // ...})\n```\n\n**Correct Usage**\n\n```\ncy.get('p')  .should(($p) => {    // ...  })  .log()// orcy.get('p').then(($p) => {  // ...  cy.log($p)})\n```\n\n#### Verify length, content, and classes from multiple `<p>`\n\n```\n<div>  <p class=\"text-primary\">Hello World</p>  <p class=\"text-danger\">You have an error</p>  <p class=\"text-default\">Try again later</p></div>\n```\n\n```\ncy.get('p').should(($p) => {  // should have found 3 elements  expect($p).to.have.length(3)  // make sure the first contains some text content  expect($p.first()).to.contain('Hello World')  // use jquery's map to grab all of their classes  // jquery's map returns a new jquery object  const classes = $p.map((i, el) => {    return Cypress.$(el).attr('class')  })  // call classes.get() to make this a plain array  expect(classes.get()).to.deep.eq([    'text-primary',    'text-danger',    'text-default',  ])})\n```\n\n**Warning** Any value returned from a `.should()` callback function will be ignored. The original subject will be yielded to the next command.\n\n```\ncy.get('p')  .should(($p) => {    expect($p).to.have.length(3)    return 'foo'  })  .then(($p) => {    // the argument $p will be the 3 elements, not \"foo\"  })\n```\n\n#### Assert class name contains `heading-`\n\n```\n<div class=\"docs-header\">  <div class=\"main-abc123 heading-xyz987\">Introduction</div></div>\n```\n\n```\ncy.get('.docs-header')  .find('div')  // .should(cb) callback function will be retried  .should(($div) => {    expect($div).to.have.length(1)    const className = $div[0].className    expect(className).to.match(/heading-/)  })  // .then(cb) callback is not retried,  // it either passes or fails  .then(($div) => {    expect($div).to.have.text('Introduction')  })\n```\n\nYou can even throw your own errors from the callback function.\n\n```\ncy.get('.docs-header')  .find('div')  .should(($div) => {    if ($div.length !== 1) {      // you can throw your own errors      throw new Error('Did not find 1 element')    }    const className = $div[0].className    if (!className.match(/heading-/)) {      throw new Error(`No class \"heading-\" in ${className}`)    }  })\n```\n\n#### Assert text content of 3 elements\n\nExample below first asserts that there are 3 elements, and then checks the text content of each one.\n\n```\n<ul class=\"connectors-list\">  <li>Walk the dog</li>  <li>Feed the cat</li>  <li>Write JavaScript</li></ul>\n```\n\n```\ncy.get('.connectors-list > li').should(($lis) => {  expect($lis).to.have.length(3)  expect($lis.eq(0)).to.contain('Walk the dog')  expect($lis.eq(1)).to.contain('Feed the cat')  expect($lis.eq(2)).to.contain('Write JavaScript')})\n```\n\nFor clarity you can pass a string message as a second argument to any `expect` assertion, see [Chai#expect](https://www.chaijs.com/guide/styles/#expect).\n\n```\ncy.get('.connectors-list > li').should(($lis) => {  expect($lis, '3 items').to.have.length(3)  expect($lis.eq(0), 'first item').to.contain('Walk the dog')  expect($lis.eq(1), 'second item').to.contain('Feed the cat')  expect($lis.eq(2), 'third item').to.contain('Write JavaScript')})\n```\n\nThese string messages will be shown in the Command Log giving each assertion more context.\n\n#### Compare text values of two elements\n\nThe example below gets the text contained within one element and saves it in a closure variable. Then the test gets the text in another element and asserts that the two text values are the same after normalizing.\n\n```\n<div class=\"company-details\">  <div class=\"title\">Acme Developers</div>  <div class=\"identifier\">ACMEDEVELOPERS</div></div>\n```\n\n```\nconst normalizeText = (s) => s.replace(/\\s/g, '').toLowerCase()// will keep text from title elementlet titleTextcy.get('.company-details')  .find('.title')  .then(($title) => {    // save text from the first element    titleText = normalizeText($title.text())  })cy.get('.company-details')  .find('.identifier')  .should(($identifier) => {    // we can massage text before comparing    const idText = normalizeText($identifier.text())    // text from the title element should already be set    expect(idText, 'ID').to.equal(titleText)  })\n```\n",
      "section": "api",
      "anchors": [
        "function"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 764
    },
    {
      "id": "api/commands/should#verify-length-content-and-classes-from-multiple-p",
      "doc_id": "api/commands/should",
      "heading": "Verify length, content, and classes from multiple <p>",
      "heading_level": 4,
      "content_markdown": "#### Verify length, content, and classes from multiple `<p>`\n\n```\n<div>  <p class=\"text-primary\">Hello World</p>  <p class=\"text-danger\">You have an error</p>  <p class=\"text-default\">Try again later</p></div>\n```\n\n```\ncy.get('p').should(($p) => {  // should have found 3 elements  expect($p).to.have.length(3)  // make sure the first contains some text content  expect($p.first()).to.contain('Hello World')  // use jquery's map to grab all of their classes  // jquery's map returns a new jquery object  const classes = $p.map((i, el) => {    return Cypress.$(el).attr('class')  })  // call classes.get() to make this a plain array  expect(classes.get()).to.deep.eq([    'text-primary',    'text-danger',    'text-default',  ])})\n```\n\n**Warning** Any value returned from a `.should()` callback function will be ignored. The original subject will be yielded to the next command.\n\n```\ncy.get('p')  .should(($p) => {    expect($p).to.have.length(3)    return 'foo'  })  .then(($p) => {    // the argument $p will be the 3 elements, not \"foo\"  })\n```\n",
      "section": "api",
      "anchors": [
        "verify-length-content-and-classes-from-multiple-p"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 181
    },
    {
      "id": "api/commands/should#assert-class-name-contains-heading",
      "doc_id": "api/commands/should",
      "heading": "Assert class name contains heading-",
      "heading_level": 4,
      "content_markdown": "#### Assert class name contains `heading-`\n\n```\n<div class=\"docs-header\">  <div class=\"main-abc123 heading-xyz987\">Introduction</div></div>\n```\n\n```\ncy.get('.docs-header')  .find('div')  // .should(cb) callback function will be retried  .should(($div) => {    expect($div).to.have.length(1)    const className = $div[0].className    expect(className).to.match(/heading-/)  })  // .then(cb) callback is not retried,  // it either passes or fails  .then(($div) => {    expect($div).to.have.text('Introduction')  })\n```\n\nYou can even throw your own errors from the callback function.\n\n```\ncy.get('.docs-header')  .find('div')  .should(($div) => {    if ($div.length !== 1) {      // you can throw your own errors      throw new Error('Did not find 1 element')    }    const className = $div[0].className    if (!className.match(/heading-/)) {      throw new Error(`No class \"heading-\" in ${className}`)    }  })\n```\n",
      "section": "api",
      "anchors": [
        "assert-class-name-contains-heading"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 140
    },
    {
      "id": "api/commands/should#assert-text-content-of-3-elements",
      "doc_id": "api/commands/should",
      "heading": "Assert text content of 3 elements",
      "heading_level": 4,
      "content_markdown": "#### Assert text content of 3 elements\n\nExample below first asserts that there are 3 elements, and then checks the text content of each one.\n\n```\n<ul class=\"connectors-list\">  <li>Walk the dog</li>  <li>Feed the cat</li>  <li>Write JavaScript</li></ul>\n```\n\n```\ncy.get('.connectors-list > li').should(($lis) => {  expect($lis).to.have.length(3)  expect($lis.eq(0)).to.contain('Walk the dog')  expect($lis.eq(1)).to.contain('Feed the cat')  expect($lis.eq(2)).to.contain('Write JavaScript')})\n```\n\nFor clarity you can pass a string message as a second argument to any `expect` assertion, see [Chai#expect](https://www.chaijs.com/guide/styles/#expect).\n\n```\ncy.get('.connectors-list > li').should(($lis) => {  expect($lis, '3 items').to.have.length(3)  expect($lis.eq(0), 'first item').to.contain('Walk the dog')  expect($lis.eq(1), 'second item').to.contain('Feed the cat')  expect($lis.eq(2), 'third item').to.contain('Write JavaScript')})\n```\n\nThese string messages will be shown in the Command Log giving each assertion more context.\n",
      "section": "api",
      "anchors": [
        "assert-text-content-of-3-elements"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 147
    },
    {
      "id": "api/commands/should#compare-text-values-of-two-elements",
      "doc_id": "api/commands/should",
      "heading": "Compare text values of two elements",
      "heading_level": 4,
      "content_markdown": "#### Compare text values of two elements\n\nThe example below gets the text contained within one element and saves it in a closure variable. Then the test gets the text in another element and asserts that the two text values are the same after normalizing.\n\n```\n<div class=\"company-details\">  <div class=\"title\">Acme Developers</div>  <div class=\"identifier\">ACMEDEVELOPERS</div></div>\n```\n\n```\nconst normalizeText = (s) => s.replace(/\\s/g, '').toLowerCase()// will keep text from title elementlet titleTextcy.get('.company-details')  .find('.title')  .then(($title) => {    // save text from the first element    titleText = normalizeText($title.text())  })cy.get('.company-details')  .find('.identifier')  .should(($identifier) => {    // we can massage text before comparing    const idText = normalizeText($identifier.text())    // text from the title element should already be set    expect(idText, 'ID').to.equal(titleText)  })\n```\n",
      "section": "api",
      "anchors": [
        "compare-text-values-of-two-elements"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 151
    },
    {
      "id": "api/commands/should#multiple-assertions",
      "doc_id": "api/commands/should",
      "heading": "Multiple Assertions",
      "heading_level": 3,
      "content_markdown": "### Multiple Assertions\n\n#### Chaining multiple assertions\n\nCypress makes it easier to chain assertions together.\n\nIn this example we use [`.and()`](/llm/markdown/api/commands/and.md) which is identical to `.should()`.\n\n```\n// our subject is not changed by our first assertion,// so we can continue to use DOM based assertionscy.get('option:first').should('be.selected').and('have.value', 'Metallica')\n```\n",
      "section": "api",
      "anchors": [
        "multiple-assertions"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 64
    },
    {
      "id": "api/commands/should#chaining-multiple-assertions",
      "doc_id": "api/commands/should",
      "heading": "Chaining multiple assertions",
      "heading_level": 4,
      "content_markdown": "#### Chaining multiple assertions\n\nCypress makes it easier to chain assertions together.\n\nIn this example we use [`.and()`](/llm/markdown/api/commands/and.md) which is identical to `.should()`.\n\n```\n// our subject is not changed by our first assertion,// so we can continue to use DOM based assertionscy.get('option:first').should('be.selected').and('have.value', 'Metallica')\n```\n",
      "section": "api",
      "anchors": [
        "chaining-multiple-assertions"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 60
    },
    {
      "id": "api/commands/should#wait-until-the-assertions-pass",
      "doc_id": "api/commands/should",
      "heading": "Wait until the assertions pass",
      "heading_level": 3,
      "content_markdown": "### Wait until the assertions pass\n\nCypress won't resolve your commands until all of its assertions pass.\n\n```\n// Application Code$('button').click(function () {  $button = $(this)  setTimeout(() => {    $button.removeClass('inactive').addClass('active')  }, 1000)})\n```\n\n```\ncy.get('button')  .click()  .should('have.class', 'active')  .and('not.have.class', 'inactive')\n```\n",
      "section": "api",
      "anchors": [
        "wait-until-the-assertions-pass"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 55
    },
    {
      "id": "api/commands/should#notes",
      "doc_id": "api/commands/should",
      "heading": "Notes",
      "heading_level": 2,
      "content_markdown": "## Notes\n\n### Subjects\n\n#### How do I know which assertions change the subject and which keep it the same?\n\nThe chainers that come from [Chai](/llm/markdown/app/references/bundled-libraries.md#Chai) or [Chai-jQuery](/llm/markdown/app/references/bundled-libraries.md#Chai-jQuery) will always document what they return.\n\n#### Using a callback function will not change what is yielded\n\nWhatever is returned in the function is ignored. Cypress always forces the command to yield the value from the previous cy command's yield (which in the example below is `<button>`)\n\n```\ncy.get('button')  .should(($button) => {    expect({ foo: 'bar' }).to.deep.eq({ foo: 'bar' })    return { foo: 'bar' } // return is ignored, .should() yields <button>  })  .then(($button) => {    // do anything we want with <button>  })\n```\n\n### Differences\n\n### What's the difference between `.then()` and `.should()`/`.and()`?\n\nUsing `.then()` allows you to use the yielded subject in a callback function and should be used when you need to manipulate some values or do some actions.\n\nWhen using a callback function with `.should()` or `.and()`, on the other hand, there is special logic to rerun the callback function until no assertions throw within it. You should be careful of side affects in a `.should()` or `.and()` callback function that you would not want performed multiple times.\n",
      "section": "api",
      "anchors": [
        "notes"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 267
    },
    {
      "id": "api/commands/should#subjects",
      "doc_id": "api/commands/should",
      "heading": "Subjects",
      "heading_level": 3,
      "content_markdown": "### Subjects\n\n#### How do I know which assertions change the subject and which keep it the same?\n\nThe chainers that come from [Chai](/llm/markdown/app/references/bundled-libraries.md#Chai) or [Chai-jQuery](/llm/markdown/app/references/bundled-libraries.md#Chai-jQuery) will always document what they return.\n\n#### Using a callback function will not change what is yielded\n\nWhatever is returned in the function is ignored. Cypress always forces the command to yield the value from the previous cy command's yield (which in the example below is `<button>`)\n\n```\ncy.get('button')  .should(($button) => {    expect({ foo: 'bar' }).to.deep.eq({ foo: 'bar' })    return { foo: 'bar' } // return is ignored, .should() yields <button>  })  .then(($button) => {    // do anything we want with <button>  })\n```\n",
      "section": "api",
      "anchors": [
        "subjects"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 147
    },
    {
      "id": "api/commands/should#how-do-i-know-which-assertions-change-the-subject-and-which-keep-it-the-same",
      "doc_id": "api/commands/should",
      "heading": "How do I know which assertions change the subject and which keep it the same?",
      "heading_level": 4,
      "content_markdown": "#### How do I know which assertions change the subject and which keep it the same?\n\nThe chainers that come from [Chai](/llm/markdown/app/references/bundled-libraries.md#Chai) or [Chai-jQuery](/llm/markdown/app/references/bundled-libraries.md#Chai-jQuery) will always document what they return.\n",
      "section": "api",
      "anchors": [
        "how-do-i-know-which-assertions-change-the-subject-and-which-keep-it-the-same"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 40
    },
    {
      "id": "api/commands/should#using-a-callback-function-will-not-change-what-is-yielded",
      "doc_id": "api/commands/should",
      "heading": "Using a callback function will not change what is yielded",
      "heading_level": 4,
      "content_markdown": "#### Using a callback function will not change what is yielded\n\nWhatever is returned in the function is ignored. Cypress always forces the command to yield the value from the previous cy command's yield (which in the example below is `<button>`)\n\n```\ncy.get('button')  .should(($button) => {    expect({ foo: 'bar' }).to.deep.eq({ foo: 'bar' })    return { foo: 'bar' } // return is ignored, .should() yields <button>  })  .then(($button) => {    // do anything we want with <button>  })\n```\n",
      "section": "api",
      "anchors": [
        "using-a-callback-function-will-not-change-what-is-yielded"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 104
    },
    {
      "id": "api/commands/should#whats-the-difference-between-then-and-should-and",
      "doc_id": "api/commands/should",
      "heading": "What's the difference between .then() and .should()/.and()?",
      "heading_level": 3,
      "content_markdown": "### What's the difference between `.then()` and `.should()`/`.and()`?\n\nUsing `.then()` allows you to use the yielded subject in a callback function and should be used when you need to manipulate some values or do some actions.\n\nWhen using a callback function with `.should()` or `.and()`, on the other hand, there is special logic to rerun the callback function until no assertions throw within it. You should be careful of side affects in a `.should()` or `.and()` callback function that you would not want performed multiple times.\n",
      "section": "api",
      "anchors": [
        "whats-the-difference-between-then-and-should-and"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 115
    },
    {
      "id": "api/commands/should#rules",
      "doc_id": "api/commands/should",
      "heading": "Rules",
      "heading_level": 2,
      "content_markdown": "## Rules\n\n### Requirements [Learn about chaining commands](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Chains-of-Commands)\n\n*   `.should()` requires being chained off a previous command.\n\n### Timeouts [Learn about timeouts](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Timeouts)\n\n*   `.should()` will continue to [retry](/llm/markdown/app/core-concepts/retry-ability.md) its specified assertions until it times out.\n\n```\n// timeout here will be passed down to the '.should()'// and it will retry for up to 10 secscy.get('input', { timeout: 10000 }).should('have.value', '10')\n```\n\n```\n// timeout here will be passed down to the '.should()'// unless an assertion throws earlier,// ALL of the assertions will retry for up to 10 secscy.get('input', { timeout: 10000 }).should(($input) => {  expect($input).to.not.be('disabled')  expect($input).to.not.have.class('error')  expect($input).to.have.value('US')})\n```\n",
      "section": "api",
      "anchors": [
        "rules"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 131
    },
    {
      "id": "api/commands/should#timeouts-learn-about-timeouts",
      "doc_id": "api/commands/should",
      "heading": "Timeouts Learn about timeouts",
      "heading_level": 3,
      "content_markdown": "### Timeouts [Learn about timeouts](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Timeouts)\n\n*   `.should()` will continue to [retry](/llm/markdown/app/core-concepts/retry-ability.md) its specified assertions until it times out.\n\n```\n// timeout here will be passed down to the '.should()'// and it will retry for up to 10 secscy.get('input', { timeout: 10000 }).should('have.value', '10')\n```\n\n```\n// timeout here will be passed down to the '.should()'// unless an assertion throws earlier,// ALL of the assertions will retry for up to 10 secscy.get('input', { timeout: 10000 }).should(($input) => {  expect($input).to.not.be('disabled')  expect($input).to.not.have.class('error')  expect($input).to.have.value('US')})\n```\n",
      "section": "api",
      "anchors": [
        "timeouts-learn-about-timeouts"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 108
    },
    {
      "id": "api/commands/should#command-log",
      "doc_id": "api/commands/should",
      "heading": "Command Log",
      "heading_level": 2,
      "content_markdown": "## Command Log\n\n**_Assert that there should be 8 children in a nav_**\n\n```\ncy.get('.left-nav>.nav').children().should('have.length', 8)\n```\n\nThe commands above will display in the Command Log as:\n\nWhen clicking on `assert` within the command log, the console outputs the following:\n",
      "section": "api",
      "anchors": [
        "command-log"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 53
    },
    {
      "id": "api/commands/should#history",
      "doc_id": "api/commands/should",
      "heading": "History",
      "heading_level": 2,
      "content_markdown": "## History\n\n| Version | Changes |\n| --- | --- |\n| [11.0.0](/llm/markdown/app/references/changelog.md#11-0-0) | Throw error if Cypress command used in callback |\n| [0.11.4](/llm/markdown/app/references/changelog.md#0-11-4) | Allows callback function argument |\n| [< 0.3.3](/llm/markdown/app/references/changelog.md#0-3-3) | `.should()` command added |\n",
      "section": "api",
      "anchors": [
        "history"
      ],
      "path": "/llm/json/chunked/api/commands/should.json",
      "token_estimate": 53
    }
  ]
}