The chai testing framework, configured with dirty-chai, chai-string and chai-equal-jsx.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
src.test
src
templates
test
.babelrc
.editorconfig
.eslintrc
.gitattributes
.gitignore
.jscsrc
.jshintrc
.npmignore
LICENSE
README.md
package.json
wallaby.conf.js

README.md

mai-chai

The chai testing framework works hand in hand with mocha. It is configured by default with following plugins:

mai-chai also includes configuration files which will be written into the ./test folder of the including project:

  • mocha.opts → registers Babel as the compiler and requires the ./test/test-helper.js file in every test.
  • test-helper.js → configures the global document, window and navigator objects.

And for Wallaby.js users, mai-chai comes with a default configuration file.

Conventions

mai-chai follows these conventions:

  • ./src → source code under test.
  • ./src.test → source code for the tests.
  • ./test → mocha configuration files.

Installing mai-chai

First install mai-chai:

npm install mai-chai --save-dev

This will also install mocha, chai, chai-as-promised, chai-asserttype, chai-equal-jsx, chai-spies, chai-string and dirty-chai.

Using mai-chai

Import expect from mai-chai, as you would from chai:

import {expect} from 'mai-chai';

and then write your BDD assertions with methods rather than properties, such as:

expect (true).to.be.true ();
foo.should.be.ok ();

or use the various assertions added by chai-string and spy on methods with chai-spies.

Configuring Wallaby.js

mai-chai provides a default Wallaby.js configuration file. If you stick to the conventions of mai-chai no other setup or configuration is required. Just point Wallaby.js to wallaby.conf.js.

Included plugins

See also Algolia's react-element-to-jsx-string which is used by chai-equal-jsx and provides the logic needed to convert a ReactElement to the corresponding JSX string.

Utility functions

  • clock() → perf, starts a high resolution timer which can be used to measure performance; it returns an opaque object.
  • clock(perf) → ms, returns the number of milliseconds elapsed.