Book Image

Learning Node.js for .NET Developers

Book Image

Learning Node.js for .NET Developers

Overview of this book

Node.js is an open source, cross-platform runtime environment that allows you to use JavaScript to develop server-side web applications. This short guide will help you develop applications using JavaScript and Node.js, leverage your existing programming skills from .NET or Java, and make the most of these other platforms through understanding the Node.js programming model. You will learn how to build web applications and APIs in Node, discover packages in the Node.js ecosystem, test and deploy your Node.js code, and more. Finally, you will discover how to integrate Node.js and .NET code.
Table of Contents (21 chapters)
Learning Node.js for .NET Developers
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

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...