Unit testing unit javascript

I am currently creating a javascript structure template as an architecture for developing the client side for the upcoming large-scale application that I will develop.

I want to go with a module observer template in which each control that I develop will have its own javascript file that does not have any sign of other controls.

From developing this structure for my application, I want to integrate it into the testing mechanism for my modules - the unit testing mechanism for javascript. I do not know about any such framework or how I can configure such. Any suggestions?

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

The library that I will use in development is jquery.

+7
source share
4 answers

The jQuery team has QUnit .

As for abstracting AJAX, you should wrap it appropriately, or just check the data processing methods.

+7
source

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

They also have a separate module to fake AJAX responses.

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

+1
source

Consider using JsTestDriver to run your JS tests. The main advantage that it provides is the ability to conduct tests in a continuous integration environment, which is important for unit testing practice.

Some additional features:

  • It can be used together with QUnit and other testing structures.
  • It can run your tests in parallel across multiple browsers.
  • It supports code code coverage.

A list of mocking libraries you can find elsewhere.

+1
source

BoilerplateJS is the reference architecture for developing a large-scale JavaScript product. You can find the tests that are written using qunit, sinon, and testr included in the folder.

0
source

All Articles