1

When we run the angular unit test it launches chrome browser or which is provided in karma.config.js. Why browser needs and what exactly happened while angular unit tests running.

Rohit Shelhalkar
  • 756
  • 1
  • 9
  • 15

1 Answers1

5

As we know there are three main components working together to help us write unit tests in angular. They are

Karma

Karma is essentially a tool which spawns a web server that executes source code against test code for each of the browsers connected. The results of each test against each browser are examined and displayed via the command line to the developer such that they can see which browsers and tests passed or failed.

A browser can be captured either manually, by visiting the URL where the Karma server is listening (typically http://localhost:9876/), or automatically by letting Karma know which browsers to start when Karma is run. Karma also watches all the files, specified within the configuration file, and whenever any file changes, it triggers the test run by sending a signal to the testing server to inform all of the captured browsers to run the test code again. Each browser then loads the source files inside an IFrame, executes the tests and reports the results back to the server.

The server collects the results from all of the captured browsers and presents them to the developer.

Jasmine

Jasmine is a behavior-driven development framework for testing JavaScript code. It does not depend on any other JavaScript frameworks. It does not require a DOM. And it has a clean, obvious syntax so that you can easily write tests. And it jasmine is consist of three main things. They are Test suits , Test specs , and Test expectations

Angular testing utitlites

These are the utility classes and function which are introduced by angular team to help the developers to write unit tests for angular. Like testing the component templates.


When we run the Angular unit test it launches Chrome browser or which is provided in karma.config.js. Why browser needs and what exactly happened while angular unit tests running.

So now you should know what is happening when we run the command ng test inside an Angular project.

After running the command angular will build the application in the watch mode and launches the karma test runner. Then karma will excute each of the test cases against the source code and display the output via the command line and the browser. (Most people find this browser output easier to read than the console log).

halfer
  • 19,824
  • 17
  • 99
  • 186
Anuradha Gunasekara
  • 6,553
  • 2
  • 27
  • 37