chai
BDD/TDD assertion library for node.js and the browser. Test framework agnostic.
Last updated 4 years ago by chai .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install chai 
SYNC missed versions from official npm registry.

ChaiJS
chai

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

downloads:? node:?
Join the Slack chat Join the Gitter chat OpenCollective Backers

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 chai.js file found within the download. For example:

<script src="./node_modules/chai/chai.js"></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:

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

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

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

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

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.

Jake Luer Veselin Todorov Keith Cirkel Lucas Fernandes da Costa Grant Snodgrass

Current Tags

  • 5.1.1                                ...           canary (6 months ago)
  • 5.1.1                                ...           latest (6 months ago)
  • 4.5.0                                ...           legacy (4 months ago)

96 Versions

  • 4.5.0                                ...           4 months ago
  • 5.1.1                                ...           6 months ago
  • 5.1.0                                ...           9 months ago
  • 5.0.3                                ...           10 months ago
  • 5.0.2                                ...           10 months ago
  • 4.4.1                                ...           10 months ago
  • 4.4.0                                ...           10 months ago
  • 5.0.0                                ...           a year ago
  • 5.0.0-rc.0                                ...           a year ago
  • 5.0.0-alpha.2                                ...           a year ago
  • 4.3.10                                ...           a year ago
  • 4.3.9                                ...           a year ago
  • 4.3.8                                ...           a year ago
  • 5.0.0-alpha.1                                ...           a year ago
  • 5.0.0-alpha.0                                ...           2 years ago
  • 4.3.7                                ...           2 years ago
  • 4.3.6                                ...           3 years ago
  • 4.3.5                                ...           3 years ago
  • 4.3.4                                ...           4 years ago
  • 4.3.3                                ...           4 years ago
  • 4.3.2                                ...           4 years ago
  • 4.3.1                                ...           4 years ago
  • 4.3.0                                ...           4 years ago
  • 4.2.0                                ...           6 years ago
  • 4.1.2                                ...           7 years ago
  • 4.1.1                                ...           7 years ago
  • 4.1.0                                ...           7 years ago
  • 4.0.2                                ...           7 years ago
  • 4.0.1                                ...           7 years ago
  • 4.0.0                                ...           7 years ago
  • 4.0.0-canary.2                                ...           8 years ago
  • 4.0.0-canary.1                                ...           8 years ago
  • 3.5.0                                ...           9 years ago
  • 3.4.1                                ...           9 years ago
  • 3.4.0                                ...           9 years ago
  • 3.3.0                                ...           9 years ago
  • 3.2.0                                ...           9 years ago
  • 3.1.0                                ...           9 years ago
  • 3.0.0                                ...           9 years ago
  • 2.3.0                                ...           10 years ago
  • 2.2.0                                ...           10 years ago
  • 2.1.2                                ...           10 years ago
  • 2.1.1                                ...           10 years ago
  • 2.1.0                                ...           10 years ago
  • 2.0.0                                ...           10 years ago
  • 1.10.0                                ...           10 years ago
  • 1.9.2                                ...           10 years ago
  • 1.9.1                                ...           11 years ago
  • 1.9.0                                ...           11 years ago
  • 1.8.1                                ...           11 years ago
  • 1.8.0                                ...           11 years ago
  • 1.7.2                                ...           11 years ago
  • 1.7.1                                ...           11 years ago
  • 1.7.0                                ...           11 years ago
  • 1.6.1                                ...           11 years ago
  • 1.6.0                                ...           12 years ago
  • 1.5.0                                ...           12 years ago
  • 1.4.2                                ...           12 years ago
  • 1.4.1                                ...           12 years ago
  • 1.4.0                                ...           12 years ago
  • 1.3.0                                ...           12 years ago
  • 1.2.0                                ...           12 years ago
  • 1.1.1                                ...           12 years ago
  • 1.1.0                                ...           12 years ago
  • 1.0.4                                ...           12 years ago
  • 1.0.3                                ...           12 years ago
  • 1.0.2                                ...           12 years ago
  • 1.0.1                                ...           12 years ago
  • 1.0.0                                ...           12 years ago
  • 0.5.3                                ...           13 years ago
  • 0.5.2                                ...           13 years ago
  • 0.5.1                                ...           13 years ago
  • 0.5.0                                ...           13 years ago
  • 0.4.2                                ...           13 years ago
  • 0.4.1                                ...           13 years ago
  • 0.4.0                                ...           13 years ago
  • 0.3.4                                ...           13 years ago
  • 0.3.3                                ...           13 years ago
  • 0.3.2                                ...           13 years ago
  • 0.3.1                                ...           13 years ago
  • 0.3.0                                ...           13 years ago
  • 0.2.4                                ...           13 years ago
  • 0.2.3                                ...           13 years ago
  • 0.2.2                                ...           13 years ago
  • 0.2.1                                ...           13 years ago
  • 0.2.0                                ...           13 years ago
  • 0.1.7                                ...           13 years ago
  • 0.1.6                                ...           13 years ago
  • 0.1.5                                ...           13 years ago
  • 0.1.4                                ...           13 years ago
  • 0.1.3                                ...           13 years ago
  • 0.1.2                                ...           13 years ago
  • 0.1.1                                ...           13 years ago
  • 0.1.0                                ...           13 years ago
  • 0.0.2                                ...           13 years ago
  • 0.0.1                                ...           13 years ago

© 2010 - cnpmjs.org x YWFE | Home | YWFE