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​
| Library | What it does | How you use it in Cypress |
|---|---|---|
| Mocha | Test framework and runner syntax | describe(), it(), beforeEach(), and other hooks |
| Chai | Assertion library | expect(), assert(), and .should() |
| Chai-jQuery | DOM-specific assertions | Chainers like have.class and be.visible on DOM subjects |
| Sinon | Spies, stubs, and fake timers | cy.spy(), cy.stub(), cy.clock(), Cypress.sinon |
| Sinon-Chai | Assertions on spies and stubs | Chainers like have.been.calledOnce |
| Lodash | General-purpose utility functions | Cypress._ |
| jQuery | DOM traversal and manipulation | Cypress.$ |
| minimatch | Glob pattern matching | Cypress.minimatch |
| blob-util | Blob and base64 conversion | Cypress.Blob |
| Buffer | Binary data handling in the browser | Cypress.Buffer |
| Bluebird | Promise library | Cypress.Promise |
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
expectandassertfunctions.
// 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()andcy.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:
Cypress._: Lodash, for working with arrays, objects, and data transformations.Cypress.$: jQuery, for DOM traversal outside of Cypress commands. DOM commands likecy.get()also yield jQuery objects.Cypress.minimatch: minimatch, for testing glob patterns against URLs or paths.Cypress.Blob: blob-util, for converting between blobs, base64 strings, and other binary formats.Cypress.Buffer: a Buffer polyfill for working with binary data in the browser, such as file uploads.Cypress.Promise: Bluebird, for creating and managing promises inside your tests.
See also​
- Assertions reference: every Chai, Chai-jQuery, and Sinon-Chai assertion available in Cypress
- Introduction to Cypress
- Writing and Organizing Tests
- Stubs, Spies, and Clocks
- Troubleshooting