Quick feedback loop

Automated testing is all about the quick feedback loop, so imagine being able to have the tests running in the console and the application refreshing on the browser after any file change. Would that be possible? The answer is yes!

Watch and run the tests

Via a simple parameter while starting Karma, we can achieve testing nirvana, as follows:

./node_modules/karma/bin/karma start karma.conf.js --auto-watch --no-single-run

Try it by yourself; run this command, change a file, and see the tests running automatically—like magic.

Once again, we don't want to remember these complicated commands, so let's add another script to the package.json file:

"scripts": {
  "test": "./node_modules/karma/bin/karma start karma.conf.js",
  "watch-test": ...

Get Jasmine JavaScript Testing - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.