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

Writing BDD-style tests with Mocha


From C# or Java, you may be most familiar with the xUnit-style of tests used by NUnit, JUnit, and so on. This style structures tests into classes, and turns method names into test names. This can be a bit restrictive, and isn't common in JavaScript testing. JavaScript test frameworks make use of the less structured, and more dynamic, nature of the language to allow more flexibility.

There are several different styles for writing tests in JavaScript. The most common is the so-called behavior-driven development (BDD) style in which we describe the behavior of our application in plain English. This is the default style of the most popular JavaScript testing frameworks. It is also common in frameworks for other programming platforms, most notably RSpec for Ruby.

We'll be using a popular test framework named Mocha. Let's first add this to our application:

> npm install mocha --save-dev

Note that --save-dev adds Mocha to our package.json file as a development...