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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access