Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

chai

> 编程语言
Open source

BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.

8.3K stars0 likes3 views
WebsiteGitHub

About

BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.


chai

Chai is a BDD / TDD assertion library for node and the browser that can be delightfully paired with any javascript testing framework.


For more information or to download plugins, view the documentation.

What is Chai?

Chai is an assertion library, similar to Node's built-in assert. It makes testing much easier by giving you lots of assertions you can run against your code.

Installation

Node.js

chai is available on npm. To install it, type:

$ npm install --save-dev chai

Browsers

You can also use it within the browser; install via npm and use the index.js file found within the download. For example:

xml
<script src="./node_modules/chai/index.js" type="module"></script>

Usage

Import the library in your code, and then pick one of the styles you'd like to use - either assert, expect or should:

javascript
import { assert } from 'chai';  // Using Assert style
import { expect } from 'chai';  // Using Expect style
import { should } from 'chai';  // Using Should style

Register the chai testing style globally

javascript
import 'chai/register-assert';  // Using Assert style
import 'chai/register-expect';  // Using Expect style
import 'chai/register-should';  // Using Should style

Import assertion styles as local variables

javascript
import { assert } from 'chai';  // Using Assert style
import { expect } from 'chai';  // Using Expect style
import { should } from 'chai';  // Using Should style
should();  // Modifies `Object.prototype`

import { expect, use } from 'chai';  // Creates local variables `expect` and `use`; useful for plugin use

Usage with Mocha

bash
mocha spec.js --require chai/register-assert.js  # Using Assert style
mocha spec.js --require chai/register-expect.js  # Using Expect style
mocha spec.js --require chai/register-should.js  # Using Should style

Read more about these styles in our docs.

Plugins

Chai offers a robust Plugin architecture for extending Chai's assertions and interfaces.

  • Need a plugin? View the official plugin list.
  • Want to build a plugin? Read the plugin api documentation.
  • Have a plugin and want it listed? Simply add the following keywords to your package.json:
    • chai-plugin
    • browser if your plugin works in the browser as well as Node.js
    • browser-only if your plugin does not work with Node.js

Related Projects

  • chaijs / chai-docs: The chaijs.com website source code.
  • chaijs / assertion-error: Custom Error constructor thrown upon an assertion failing.
  • chaijs / deep-eql: Improved deep equality testing for Node.js and the browser.
  • chaijs / check-error: Error comparison and information related utility for Node.js and the browser.
  • chaijs / loupe: Inspect utility for Node.js and browsers.
  • chaijs / pathval: Object value retrieval given a string path.

Contributing

Thank you very much for considering to contribute!

Please make sure you follow our Code Of Conduct and we also strongly recommend reading our Contributing Guide.

Here are a few issues other contributors frequently ran into when opening pull requests:

  • Please do not commit changes to the chai.js build. We do it once per release.
  • Before pushing your commits, please make sure you rebase them.

Contributors

Please see the full Contributors Graph for our list of contributors.

Core Contributors

Feel free to reach out to any of the core contributors with your questions or concerns. We will do our best to respond in a timely manner.

Core Contributor Alumni

This project would not be what it is without the contributions from our prior core contributors, for whom we are forever grateful:

Issues· 93 open

View all issuesOpen on GitHub
  • #1712

    Dependency Dashboard

    Updated Sep 29, 2026
  • #1287

    Break debugger on assertion

    Updated Sep 5, 2026
  • #1314

    Typescript test says error TS2339: Property 'by' does not exist on type 'Assertion'.

    Updated Sep 5, 2026
  • #1328

    Bug/To.have.all.keys broken

    Updated Sep 5, 2026
  • #1404

    Error: getaddrinfo ENOTFOUND with Docker in chai test

    Updated Sep 5, 2026
  • #1492

    Security vulnerability - Prototype pollution found in npm package - chai

    Updated Sep 5, 2026
  • #1554

    Officia type definitions for 5.x?

    typesUpdated Sep 5, 2026
  • #1728

    `truncateThreshold: 0` prints `process` and triggers DeprecationWarning

    Updated Nov 12, 2025
  • #1708

    Disable loupe's `customInspect` option to avoid collisions.

    Updated Oct 2, 2025
  • #1302

    chai plugin with html diff

    Updated Aug 29, 2025

> Tags

JavaScriptassertionsbddchaijavascript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedOct 1, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言