blob: 78e4d2dead13bf56ca6a8ce50ee6e842dc34c334 [file] [log] [blame] [view]
Yang Guo4fd355c2019-09-19 08:59:031<h1 align=center>
2 <a href="http://chaijs.com" title="Chai Documentation">
3 <img alt="ChaiJS" src="http://chaijs.com/img/chai-logo.png">
4 </a>
5 <br>
6 chai
7</h1>
8
9<p align=center>
10 Chai is a BDD / TDD assertion library for <a href="http://nodejs.org">node</a> and the browser that can be delightfully paired with any javascript testing framework.
11</p>
12
13<p align=center>
14 <a href="./LICENSE">
15 <img
16 alt="license:mit"
17 src="https://img.shields.io/badge/license-mit-green.svg?style=flat-square"
18 />
19 </a>
20 <a href="https://github.com/chaijs/chai/releases">
21 <img
22 alt="tag:?"
23 src="https://img.shields.io/github/tag/chaijs/chai.svg?style=flat-square"
24 />
25 </a>
26 <a href="https://www.npmjs.com/package/chai">
27 <img
28 alt="node:?"
Tim van der Lippe0a9b84d2021-03-24 11:53:1529 src="https://img.shields.io/badge/node-%3E=4.0-blue.svg?style=flat-square"
Yang Guo4fd355c2019-09-19 08:59:0330 />
31 </a>
32 <br/>
33 <a href="https://saucelabs.com/u/chaijs">
34 <img
35 alt="Selenium Test Status"
36 src="https://saucelabs.com/browser-matrix/chaijs.svg"
37 />
38 </a>
39 <br/>
40 <a href="https://www.npmjs.com/packages/chai">
41 <img
42 alt="downloads:?"
43 src="https://img.shields.io/npm/dm/chai.svg?style=flat-square"
44 />
45 </a>
46 <a href="https://travis-ci.org/chaijs/chai">
47 <img
48 alt="build:?"
49 src="https://img.shields.io/travis/chaijs/chai/master.svg?style=flat-square"
50 />
51 </a>
52 <a href="https://codecov.io/gh/chaijs/chai">
53 <img
54 alt="coverage:?"
55 src="https://img.shields.io/codecov/c/github/chaijs/chai.svg?style=flat-square"
56 />
57 </a>
58 <a href="">
59 <img
60 alt="devDependencies:?"
61 src="https://img.shields.io/david/chaijs/chai.svg?style=flat-square"
62 />
63 </a>
64 <br/>
65 <a href="https://chai-slack.herokuapp.com/">
66 <img
67 alt="Join the Slack chat"
68 src="https://img.shields.io/badge/slack-join%20chat-E2206F.svg?style=flat-square"
69 />
70 </a>
71 <a href="https://gitter.im/chaijs/chai">
72 <img
73 alt="Join the Gitter chat"
74 src="https://img.shields.io/badge/gitter-join%20chat-D0104D.svg?style=flat-square"
75 />
76 </a>
77 <a href="https://opencollective.com/chaijs">
78 <img
79 alt="OpenCollective Backers"
80 src="https://opencollective.com/chaijs/backers/badge.svg?style=flat-square"
81 />
82 </a>
83</p>
84
85For more information or to download plugins, view the [documentation](http://chaijs.com).
86
87## What is Chai?
88
89Chai 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.
90
91## Installation
92
93### Node.js
94
95`chai` is available on [npm](http://npmjs.org). To install it, type:
96
Tim van der Lippec7b05fe2021-02-12 15:43:3197 $ npm install --save-dev chai
Yang Guo4fd355c2019-09-19 08:59:0398
99### Browsers
100
101You can also use it within the browser; install via npm and use the `chai.js` file found within the download. For example:
102
103```html
104<script src="./node_modules/chai/chai.js"></script>
105```
106
107## Usage
108
109Import the library in your code, and then pick one of the styles you'd like to use - either `assert`, `expect` or `should`:
110
111```js
112var chai = require('chai');
113var assert = chai.assert; // Using Assert style
114var expect = chai.expect; // Using Expect style
115var should = chai.should(); // Using Should style
116```
117
118### Pre-Native Modules Usage (_registers the chai testing style globally_)
119
120```js
121require('chai/register-assert'); // Using Assert style
122require('chai/register-expect'); // Using Expect style
123require('chai/register-should'); // Using Should style
124```
125
126### Pre-Native Modules Usage (_as local variables_)
127
128```js
129const { assert } = require('chai'); // Using Assert style
130const { expect } = require('chai'); // Using Expect style
131const { should } = require('chai'); // Using Should style
132should(); // Modifies `Object.prototype`
133
134const { expect, use } = require('chai'); // Creates local variables `expect` and `use`; useful for plugin use
135```
136
137### Native Modules Usage (_registers the chai testing style globally_)
138
139```js
140import 'chai/register-assert'; // Using Assert style
141import 'chai/register-expect'; // Using Expect style
142import 'chai/register-should'; // Using Should style
143```
144
145### Native Modules Usage (_local import only_)
146
147```js
148import { assert } from 'chai'; // Using Assert style
149import { expect } from 'chai'; // Using Expect style
150import { should } from 'chai'; // Using Should style
151should(); // Modifies `Object.prototype`
152```
153
154### Usage with Mocha
155
156```bash
157mocha spec.js -r chai/register-assert # Using Assert style
158mocha spec.js -r chai/register-expect # Using Expect style
159mocha spec.js -r chai/register-should # Using Should style
160```
161
162[Read more about these styles in our docs](http://chaijs.com/guide/styles/).
163
164## Plugins
165
166Chai offers a robust Plugin architecture for extending Chai's assertions and interfaces.
167
168- Need a plugin? View the [official plugin list](http://chaijs.com/plugins).
169- Want to build a plugin? Read the [plugin api documentation](http://chaijs.com/guide/plugins/).
170- Have a plugin and want it listed? Simply add the following keywords to your package.json:
171 - `chai-plugin`
172 - `browser` if your plugin works in the browser as well as Node.js
173 - `browser-only` if your plugin does not work with Node.js
174
175### Related Projects
176
177- [chaijs / chai-docs](https://github.com/chaijs/chai-docs): The chaijs.com website source code.
178- [chaijs / assertion-error](https://github.com/chaijs/assertion-error): Custom `Error` constructor thrown upon an assertion failing.
179- [chaijs / deep-eql](https://github.com/chaijs/deep-eql): Improved deep equality testing for Node.js and the browser.
180- [chaijs / type-detect](https://github.com/chaijs/type-detect): Improved typeof detection for Node.js and the browser.
181- [chaijs / check-error](https://github.com/chaijs/check-error): Error comparison and information related utility for Node.js and the browser.
182- [chaijs / loupe](https://github.com/chaijs/loupe): Inspect utility for Node.js and browsers.
183- [chaijs / pathval](https://github.com/chaijs/pathval): Object value retrieval given a string path.
184- [chaijs / get-func-name](https://github.com/chaijs/get-func-name): Utility for getting a function's name for node and the browser.
185
186### Contributing
187
188Thank you very much for considering to contribute!
189
190Please make sure you follow our [Code Of Conduct](https://github.com/chaijs/chai/blob/master/CODE_OF_CONDUCT.md) and we also strongly recommend reading our [Contributing Guide](https://github.com/chaijs/chai/blob/master/CONTRIBUTING.md).
191
192Here are a few issues other contributors frequently ran into when opening pull requests:
193
194- Please do not commit changes to the `chai.js` build. We do it once per release.
195- Before pushing your commits, please make sure you [rebase](https://github.com/chaijs/chai/blob/master/CONTRIBUTING.md#pull-requests) them.
196
197### Contributors
198
199Please see the full
200[Contributors Graph](https://github.com/chaijs/chai/graphs/contributors) for our
201list of contributors.
202
203### Core Contributors
204
205Feel free to reach out to any of the core contributors with your questions or
206concerns. We will do our best to respond in a timely manner.
207
208[![Jake Luer](https://avatars3.githubusercontent.com/u/58988?v=3&s=50)](https://github.com/logicalparadox)
209[![Veselin Todorov](https://avatars3.githubusercontent.com/u/330048?v=3&s=50)](https://github.com/vesln)
210[![Keith Cirkel](https://avatars3.githubusercontent.com/u/118266?v=3&s=50)](https://github.com/keithamus)
211[![Lucas Fernandes da Costa](https://avatars3.githubusercontent.com/u/6868147?v=3&s=50)](https://github.com/lucasfcosta)
212[![Grant Snodgrass](https://avatars3.githubusercontent.com/u/17260989?v=3&s=50)](https://github.com/meeber)