{
  "doc": {
    "id": "api/utilities/sinon",
    "title": "Cypress.sinon",
    "description": "Cypress automatically includes Sinon.JS and exposes it as Cypress.sinon.",
    "section": "api",
    "source_path": "/llm/markdown/api/utilities/sinon.md",
    "version": "48b03b5502f7aea1d0454750cce208f775403542",
    "updated_at": "2026-05-20T19:00:20.270Z",
    "headings": [
      {
        "id": "api/utilities/sinon#cypress-sinon",
        "text": "Cypress.sinon",
        "level": 1
      },
      {
        "id": "api/utilities/sinon#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/utilities/sinon#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/utilities/sinon#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/utilities/sinon#match-string",
        "text": "match.string",
        "level": 3
      },
      {
        "id": "api/utilities/sinon#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "content": {
    "type": "root",
    "children": [
      {
        "type": "heading",
        "depth": 1,
        "children": [
          {
            "type": "text",
            "value": "Cypress.sinon"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Cypress automatically includes "
          },
          {
            "type": "link",
            "title": null,
            "url": "http://sinonjs.org/",
            "children": [
              {
                "type": "text",
                "value": "Sinon.JS"
              }
            ]
          },
          {
            "type": "text",
            "value": " and exposes it as `Cypress.sinon`. Because commands "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/spy.md",
            "children": [
              {
                "type": "text",
                "value": "`cy.spy`"
              }
            ]
          },
          {
            "type": "text",
            "value": " and "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/stub.md",
            "children": [
              {
                "type": "text",
                "value": "`cy.stub`"
              }
            ]
          },
          {
            "type": "text",
            "value": " are already wrapping Sinon methods, the most common use for `Cypress.sinon` is to provide flexible "
          },
          {
            "type": "link",
            "title": null,
            "url": "https://sinonjs.org/releases/latest/matchers/",
            "children": [
              {
                "type": "text",
                "value": "matchers"
              }
            ]
          },
          {
            "type": "text",
            "value": " when doing assertions."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Syntax"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "Cypress.sinon.match(value)Cypress.sinon.match.<matcher name>"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Usage"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Correct Usage"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "Cypress.sinon.match.string"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Incorrect Usage"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.sinon.match.string // Errors, cannot be chained off 'cy'"
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Examples"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "`match.string`"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "This example comes from the recipe "
          },
          {
            "type": "link",
            "title": null,
            "url": "https://github.com/cypress-io/cypress-example-recipes#testing-the-dom",
            "children": [
              {
                "type": "text",
                "value": "Root style"
              }
            ]
          },
          {
            "type": "text",
            "value": ". Imagine an application code where the method `setProperty` is called to change a CSS variable:"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "document.querySelector('input[type=color]').addEventListener('change', (e) => {  document.documentElement.style.setProperty(    '--background-color',    e.target.value  )})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "We can write a test to confirm that the method `setProperty` was called with two strings; we don't care about value of the first string, but we do want to check if it was indeed a string."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.document()  .its('documentElement.style')  .then((style) => {    cy.spy(style, 'setProperty').as('setColor')  })cy.get('input[type=color]').invoke('val', '#ff0000').trigger('change')// we don't care about '--background-color' exact// value but know it should be a stringcy.get('@setColor').should(  'have.been.calledWith',  Cypress.sinon.match.string,  '#ff0000')"
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "See also"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "https://example.cypress.io/commands/spies-stubs-clocks",
                    "children": [
                      {
                        "type": "text",
                        "value": "Spies, stubs & clocks"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " example page"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "https://sinonjs.org/releases/latest/matchers/",
                    "children": [
                      {
                        "type": "text",
                        "value": "Sinon matchers"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " documentation page"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/bundled-libraries.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "Bundled Libraries"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/spy.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`cy.spy()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/stub.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`cy.stub()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/guides/stubs-spies-and-clocks.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "Stubs, Spies, and Clocks"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " guide"
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  },
  "token_estimate": 253
}