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.
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 styleimport { expect } from 'chai'; // Using Expect styleimport { should } from 'chai'; // Using Should style
Register the chai testing style globally
import 'chai/register-assert'; // Using Assert styleimport 'chai/register-expect'; // Using Expect styleimport 'chai/register-should'; // Using Should style
Import assertion styles as local variables
import { assert } from 'chai'; // Using Assert styleimport { expect } from 'chai'; // Using Expect styleimport { should } from 'chai'; // Using Should styleshould(); // 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 stylemocha spec.js --require chai/register-expect.js # Using Expect stylemocha spec.js --require chai/register-should.js # Using Should style