Unit testing JavaScript applications can seem difficult. Issues arise with JavaScript scope, asynchronous XHR requests, DOM manipulation, and all the different browsers and platforms. Sometimes, JavaScript unit testing seems unreliable, brittle, or take more time and effort than it’s worth. The good news is that dozens of JavaScript test frameworks, libraries, and test runners help solve the problems. These make implementing unit tests for your JavaScript applications quick, reliable, and easy to maintain.
The bad news is, there are dozens of JavaScript frameworks, libraries, and test runners to choose from. Selecting a JavaScript test framework can be daunting. This article discusses the basics for writing JavaScript unit tests, the concepts behind test-driven development (TDD) and behavior-driven development (BDD). You will be able to apply that information to writing and running JavaScript unit tests with Jasmine. Jasmine is a behavior-driven development framework for testing your JavaScript code. It does not depend on any other JavaScript frameworks. It does not require a DOM. And it has a clean, obvious syntax so that you can easily write tests.