node package manager
Painless code sharing. npm Orgs help your team discover, share, and reuse code. Create a free org »


Assertive Chai

Chai.JS without Expect or Should


This is just the Assert API from Chai.JS. When run in Node.JS, it depends on the built-in assert module. When run in the browser, it depends on the browser port of those assertions.

The unit tests are stolen from Chai.JS in part.


I'm leaning on Node.js' implementation of deepEqual and I need to borrow Chai's instead, so:

  • deep-equality assertion for objects with circular references isn't working yet

  • deep-equality assertion for objects like Object.create({ ... }) isn't working either

Likewise, I'm leaning on Node.js' implementation of throws and doesNotThrow, so:

  • assertions on the content of a thrown error aren't working yet


  • Chai.JS requires ECMAScript 5, making it a poor choice for projects that need to span a wide variety of browsers

  • I don't feel BDD-style assertions are worth the hassle of having to learn what is frequently an inconsistent API

  • BDD makes more sense at the test framework level, and it's easy to integrate Chai.JS (and this library) with any test framework you like



bower install assertive-chai --save-dev
<script src="bower_components/assertive-chai/dist/assertive-chai.js"></script>
var assert = chai.assert;

Be sure to include ES5 shims if you need to test in IE8, and a JSON polyfill for testing in IE7.


Frankly, I'd probably just stick with upstream Chai for Node.JS (as there aren't any ES5 compatibility issues with Node.JS), but if you like:

npm install assertive-chai --save-dev
var assert = require('assertive-chai').assert;


  • generate the browser bundle: npm run build
  • generate browser tests bundle and run Node.js tests: npm test
  • run the browser tests by navigating to the HTML files in the tests directory


Related Stuff

  • see my tape-chai project if you prefer the simplicity of tape but miss some of the more convenient assertions from chai