Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unit testing modular javascript

I am currently deriving a javascript framework pattern as an architecture for the client side development for an upcoming large scale application that I will developing.

I am looking to go with a module observer pattern in which each control I develop will have its own javascript file, holding no knoweldge of the other controls.

From designing this framework for my application, I am looking to integrate in a testing mechanism for my modules - a unit testing mechanism for javascript. I am not aware of any such frameworks or how I may set up such. Any suggestions?

As part of such testing, I will also need to mock up http requests.

The library I will be using in development is jquery.

like image 460
amateur Avatar asked Sep 13 '11 22:09

amateur


3 Answers

The JQuery team has QUnit.

As for abstracting out AJAX, you should wrap it appropriately or just test the data manipulation methods.

like image 183
Daniel A. White Avatar answered Oct 17 '22 06:10

Daniel A. White


Jasmine may be what you are looking for. It has built-in mock up support, and does not rely on any other frameworks.

They also have a separate module for faking AJAX responses.

The setup is simple. Just download the standalone version, write some testing suites, and view the SpecRunner.html in a browser.

like image 41
nfang Avatar answered Oct 17 '22 06:10

nfang


Consider using JsTestDriver to run your JS tests. The main benefit it provides - it can run your tests on continuous integration environment, which is essential for unit testing practice.

Some additional features:

  1. It can be used along with QUnit and other testing frameworks.
  2. It can execute your tests in parallel across multiple browser.
  3. It supports calculation code coverage.

List of mocking libraries you can find in another thread.

like image 43
Yauheni Sivukha Avatar answered Oct 17 '22 05:10

Yauheni Sivukha