Book Image

Node.js By Example

Book Image

Node.js By Example

Overview of this book

Table of Contents (18 chapters)
Node.js By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Introducing the basic testing toolset


Before writing the tests, we will spend some time talking about the testing toolset. We need some instruments to define and run our tests.

The testing framework

In the context of JavaScript, the testing framework is a set of functions that help you organize the tests into logical groups. There are framework functions such as suite, describe, test, or it that define the structure of our suite. Here is a short example:

describe('Testing database communication', function () {
  it('should connect to the database', function(done) {
    // the actual testing goes here
  });
  it('should execute a query', function(done) {
    // the actual testing goes here
  });
});

We used the describe function to wrap the more detailed tests (it) into a group. Organizing the group in such a way helps us keep focus and at the same time, it is quite informative.

Some popular testing frameworks in the JavaScript community are QUnit, Jasmine, and Mocha.

The assertion library

What...