Skip to main content
Cypress App

Bundled Libraries

Cypress ships with a set of proven open source testing libraries built in: Mocha structures your tests, Chai powers your assertions, and Sinon provides spies and stubs, alongside utility libraries like Lodash and jQuery. You don't install, import, or configure any of them. They're bundled inside Cypress and ready to use in every test.

If you've written JavaScript tests before, these tools will feel familiar, and what you already know about them carries over directly to Cypress.

What's included​

LibraryWhat it doesHow you use it in Cypress
MochaTest framework and runner syntaxdescribe(), it(), beforeEach(), and other hooks
ChaiAssertion libraryexpect(), assert(), and .should()
Chai-jQueryDOM-specific assertionsChainers like have.class and be.visible on DOM subjects
SinonSpies, stubs, and fake timerscy.spy(), cy.stub(), cy.clock(), Cypress.sinon
Sinon-ChaiAssertions on spies and stubsChainers like have.been.calledOnce
LodashGeneral-purpose utility functionsCypress._
jQueryDOM traversal and manipulationCypress.$
minimatchGlob pattern matchingCypress.minimatch
blob-utilBlob and base64 conversionCypress.Blob
BufferBinary data handling in the browserCypress.Buffer
BluebirdPromise libraryCypress.Promise
info

Cypress always uses its own bundled versions of these libraries. Installing a different version of Mocha, Chai, or Sinon in your project won't change the version Cypress runs, and no version needs to be installed for Cypress to work.

If you write your tests in TypeScript, note that Cypress also ships type definitions for these bundled globals. Projects that install @types/chai or @types/jquery, or that run Jest alongside Cypress, can end up with clashing global types. See Configure tsconfig.json and Clashing types with Jest for the recommended setup.

Mocha​

Cypress uses Mocha's bdd interface to structure and run your tests. Every test you write, whether end-to-end or component, sits on the harness Mocha provides:

describe('Checkout', () => {
beforeEach(() => {
cy.visit('/cart')
})

it('completes an order', () => {
// test body
})
})

Cypress extends Mocha under the hood, smoothing over edge cases and improving error messages. These changes are transparent: you write standard Mocha syntax, and Cypress handles the rest.

Read our guide on writing and organizing tests for how to structure specs with Mocha's syntax.

Chai​

While Mocha structures your tests, Chai gives you readable assertions with clear error messages. Every assertion in Cypress is built on Chai, and you can use it two ways:

  • Implicitly, by chaining .should() or .and() off a Cypress command. Cypress applies the Chai assertion to the command's subject and retries it until it passes or times out.
  • Explicitly, with the globally available expect and assert functions.
// implicit, retried automatically
cy.get('[data-testid="greeting"]').should('contain', 'Jane')

// explicit
expect(user.name).to.equal('Jane')

The bundled Chai is also extensible. Install any Chai plugin, register it with chai.use() in your support file, and its assertions work in both expect() and .should(). See Adding New Assertions for details.

See the full list of available Chai assertions.

Chai-jQuery​

Most end-to-end assertions are about the DOM. Cypress bundles Chai-jQuery, which extends Chai with jQuery-specific chainers, so you can assert directly on the elements your commands yield:

cy.get('[data-testid="submit"]').should('have.class', 'active')
cy.get('[data-testid="modal"]').should('be.visible')

See the full list of available Chai-jQuery assertions.

Sinon​

When you need to verify or control how functions behave, Cypress provides Sinon's test doubles through built-in commands:

  • cy.spy() wraps a function to record its calls without changing its behavior.
  • cy.stub() replaces a function and controls its behavior.
  • cy.clock() and cy.tick() control time in your application using Sinon's fake timers.

Cypress also exposes the full library as Cypress.sinon, so Sinon's matchers and other APIs are available anywhere in your tests.

Read our guide on stubs, spies, and clocks for patterns and examples.

Sinon-Chai​

To assert on spies and stubs with the same .should() syntax you use everywhere else, Cypress bundles Sinon-Chai, which extends Chai with Sinon-specific chainers:

const stub = cy.stub().as('alert')

cy.on('window:alert', stub)
cy.get('[data-testid="delete"]').click()
cy.get('@alert').should('have.been.calledOnce')

See the full list of available Sinon-Chai assertions.

Utility libraries​

Cypress also bundles these libraries on the Cypress object. They're available anywhere in your tests, with no imports required:

See also​