Using Chai for assertions
Another way to make our tests more descriptive is how we write our assertions. Although the built-in Node.js assert module has been useful so far, it is a bit limited. It only contains a small number of simple methods for basic assertions.
You may have experience of Fluent Assertions or NUnit's Constraint model in .NET, or AssertJ in Java. Compared to these, the Node.js assert module might seem quite primitive.
There are several assertion frameworks available for JavaScript. We'll be using Chai (http://chaijs.com), which supports three different styles for writing assertions. The assert
style follows the traditional xUnit assertions, as in JUnit, or the classic model of NUnit. The should
and expect
styles provide a natural language interface for building more descriptive assertions.
Any of these styles is a perfectly valid choice for writing test assertions. The important thing is to pick a style for your codebase and use it consistently. We will be using Chai's expect...