piątek, 8 listopada 2013

AngularJS example MotoAds unit tests

Unit tests result: Application folders tree:
In Angular the controller is separated from the view so it is easy to add the unit tests to MotoAds application. Recall the controller code which will be tested (controllers.js): We should write the script for running unit tests (test.bat): We configure Karma for our tests (karma.conf.js): When everything is ready we can start writing tests in controllersSpec.js.

Step 1
We prepare dummy data:
Step 2
Load modules, define dummy services, initialize scope, controller and filter:
Step 3
We write first test - filtering by brand and model:
Step 4
We write second test - filtering by country and region:
Step 5
We write third test - filtering by year:
Step 6
We write fourth test - sorting by year:
Step 7
We run unit test in Node.js command prompt by running test.bat and we should see:
If you want to run this example on your computer, you can download sources from GitHub.

Any comment would be highly appreciated.

Brak komentarzy: