Running Tests with AngularJS, Karma and Jasmine
When running the JavaScript tests on our current codebase, it takes too long to initialize and run tests. This is big slowdown, especially for someone who doesn’t have much experience with Jasmine or Angular.
Ideally for me would be if I could:
- run specific tests
- being able to breakpoint and debug test in Chrome Dev tools
- auto update, so I could just add line of code to test and refresh the page
The following changes might be specicific for our codebase setup.
How To Do It
-
When running tests, use
fdiscribe
andfit
which will focus on specific spec or sepcific test. (Jasmin focused_spec.js) -
Install
karma-cli
(StackOverflow #1)npm install karma-cli -g
-
In static/karma.conf.js set
autoWatch
to be True, so the new changes in files will be automatically picked up. (Newtriks LTD blog)autoWatch: true
-
Run tests using
karma-cli
(StackOverflow #2)$> cd project_folder
$> cd static
$> karma start karma.conf.js --browser=Chrome --single-run=false --reports=html
-
After the
karma
test starts, the new Chrome window will open up. Click on Debug in new window. -
In new tab, open developers tools and you have access to all running tests.
When you edit your tests or specs, just refresh the tab with developer console open and the changes should be immediately visible.