Introduction of Jasmine & Karma


In this article we will learn how to write unit tests in for services and component in an Angular app using the Jasmine framework and karma .

Before proceeding with Angular unit test case , we should have knowledge on angular.

You can learn angular 8 from below link

What is Jasmine

  1. Jasmine is an open-source JavaScript testing framework.
  2. JavaScript testing framework provides building blocks to write JavaScript unit test cases so each line of JavaScript statement is properly unit tested. 
  3. It is used to test any type of JavaScript application.
  4. Jasmine is a BDD (Behavior Driven Development)
  5.  In BDD Test are written in Non-technical language so everyone can understand it easily.
  6.  BDD manly focus on the testing the behavior of code rather than implementation.     
  7. By following BDD procedure, Jasmine provides a small syntax to test the smallest unit of the entire application instead of testing it as a whole.
  8. It does not depend on any other JavaScript frameworks. 
  9. It does not require a DOM, And it has a clean, obvious syntax so that you can easily write tests.
  10. Jasmine support asynchronous testing.
  11. Jasmine has the test double functions called spies , A spy can stub any function and track all calls to it and its arguments 

What is Karma

  1. Karma is a testing automation tool created by the Angular JS team.
  2. Karma is Open source tool.
  3. Karma is a tool made on top of NodeJS to run JavaScript test cases. 
  4. This is not a testing framework like Jasmine or Mocha or Chai etc 
  5. It only allows us to run JavaScript test cases written using testing frameworks like Jasmine.
  6. Karma allow us to execute the test cases on any browsers.
  7. Karma runs JavaScript test cases against real browsers through Command Line Interface (CLI) rather than virtual browser and DOM. Since, DOM rendering across browsers vary, so for correctness of the test report it uses real browsers. 
  8. It can be configured what all browsers need to be used while running Karma.
  9. Karma can we configured with continuous integration tools like Travis, Jenkin etc.

Share this

Related Posts

Next Post »