- Notifications
You must be signed in to change notification settings - Fork703
BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.
License
chaijs/chai
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Chai is a BDD / TDD assertion library fornode and the browser that can be delightfully paired with any javascript testing framework.
For more information or to download plugins, view thedocumentation.
Chai is anassertion library, similar to Node's built-inassert
. It makes testing much easier by giving you lots of assertions you can run against your code.
chai
is available onnpm. To install it, type:
$ npm install --save-dev chai
You can also use it within the browser; install via npm and use thechai.js
file found within the download. For example:
<scriptsrc="./node_modules/chai/chai.js"></script>
Import the library in your code, and then pick one of the styles you'd like to use - eitherassert
,expect
orshould
:
import{assert}from'chai';// Using Assert styleimport{expect}from'chai';// Using Expect styleimport{should}from'chai';// Using Should style
import'chai/register-assert';// Using Assert styleimport'chai/register-expect';// Using Expect styleimport'chai/register-should';// Using Should style
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
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
Read more about these styles in our docs.
Chai offers a robust Plugin architecture for extending Chai's assertions and interfaces.
- Need a plugin? View theofficial plugin list.
- Want to build a plugin? Read theplugin 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.jsbrowser-only
if your plugin does not work with Node.js
- 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.
Thank you very much for considering to contribute!
Please make sure you follow ourCode Of Conduct and we also strongly recommend reading ourContributing 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 yourebase them.
Please see the fullContributors Graph for ourlist of contributors.
Feel free to reach out to any of the core contributors with your questions orconcerns. We will do our best to respond in a timely manner.
About
BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.