Book Image

CoffeeScript Application Development Cookbook

By : Mike Hatfield
Book Image

CoffeeScript Application Development Cookbook

By: Mike Hatfield

Overview of this book

Table of Contents (18 chapters)
CoffeeScript Application Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Unit testing with QUnit


QUnit is a popular testing framework for JavaScript that supports a Test Driven Design (TDD) approach to writing tests.

When using QUnit, we write our tests in the form of CoffeeScript functions that describe our desired functionality. When these tests are run, the QUnit test runner will execute our tests against our application's code and display the test results.

In this recipe, we will demonstrate how to configure QUnit and write a variety of tests to verify that our CoffeeScript code is working as expected.

Getting ready

We will begin by downloading the QUnit package and configuring the test runner.

QUnit can be installed in a variety of ways. We will be using Node's bower package installer to grab the QUnit files we need.

Bower is a package manager similar to NPM, but where NPM specializes in server-side packages, bower specializes in frontend packages. To install bower, use the following command:

npm install -g bower

With bower installed, we can install QUnit using...