BDD Style Introduction
The BDD style is exposed through expect
or should
interfaces. In both
scenarios, you chain together natural language assertions.
// expect
var expect = require('chai').expect;
expect(foo).to.equal('bar');
// should
var should = require('chai').should();
foo.should.equal('bar');
Differences
The expect
interface provides a function as a starting point for chaining
your language assertions. It works on both node.js and in the browser.
The should
interface extends Object.prototype
to provide a single getter as
the starting point for your language assertions. Most browser don't like
extensions to Object.prototype
so it is not recommended for browser use.
Configuration
By default, Chai does not show stack traces upon an AssertionError. This can
be changed by modifying the includeStack
parameter for chai.Assertion. For example:
var chai = require('chai');
chai.Assertion.includeStack = true; // defaults to false