chai


chai : Chai is a BDD / TDD assertion library for node and the browser that can be delightfully paired with any javascript testing framework.

Assertion interfaces and styles
There are two popular way of assertion in Chai, expect and should
The expect interface provides function for assertion.
The should interface extends each object with a should property for assertion.
should property gets added to the Object.Prototype, so that all object can access it through prototype chain.

Installation:
npm install chai

Usage:

The describe and it block are coming from mocha (test runner).
expect should
Output:

EXPECT:
SHOULD:

The should style allows for the same chainable assertions as the expect interface, however it extends each object with a should property to start your chain.
Note: The expect require is just a reference to the expect function, whereas with the should require, the function is being executed.
Output:

References:
https://www.npmjs.com/package/chai
https://www.chaijs.com/guide/styles/

Comments

Popular Posts