What is Jasmine?

Get introduced to the Jasmine testing framework.

Jasmine is a framework we can use to write tests for JavaScript. It can be used to test vanilla JavaScript applications and other applications written using frameworks such as Angular. We will use a test runner called Karma to run our tests in a headless Chrome browser.

Unit tests take one part of our code, such as a method or class, and test it to see if it works in isolation. When a unit test fails, we know that the failure was caused by the part of the code that it’s testing. We can generally jump straight to the class or method and fix the bug.

Feature tests

Feature tests are concerned with testing the system to see if it works as a whole. For example, a feature test might visit a page in our application, complete a form, and check if the user is redirected to the correct route. Feature tests are like casting a fishing net. They can cover a lot of ground in finding bugs, but if they fail, it might take us some time to work out where the problem lies.

Most of the tests we write should be unit tests because they run quickly and provide the most helpful feedback. However, we also need some feature tests to ensure that our system works as a whole. Jasmine is used for writing unit tests, whereas other tools, such as Protractor, are more suited to writing feature tests.