Book Image

Node.js Blueprints

By : Krasimir Stefanov Tsonev
Book Image

Node.js Blueprints

By: Krasimir Stefanov Tsonev

Overview of this book

A straightforward, practical guide containing step-by-step tutorials that will push your Node.js programming skills to the next level. If you are a web developer with experience in writing client-side JavaScript and want to discover the fascinating world of Node.js to develop fast and efficient web and desktop applications, then this book is for you.
Table of Contents (14 chapters)
13
Index

Using Jasmine


Jasmine is a framework to test the JavaScript code. It is available as a Node.js module and also as a library, which we can use in the browser. It comes with its own assertion methods.

Installing Jasmine

We are going to use the Node.js version of the framework. It's a module, so it can be installed via the Node.js package manager, npm, as shown in the following code line:

npm install jasmine-node -g

The preceding command will set up Jasmine globally, so we can run jasmine-node in every directory of our choice. The tests could be organized into different files placed in one folder or in subfolders. The only requirement is to end the filenames with spec.js, for example, testing-payments.spec.js or testing-authorization.spec.js.

Defining the module for testing

Before we write the actual test, let's define the application we want to build. Let's say we need a Node.js module that reads a file and finds specific words inside it. The following is the basic file structure that we are starting...