Skip to main content

Posts

Showing posts from June, 2017

Unit Testing AngularJS with Jasmine

As a developer, I was running away from writing unit tests of UI. However, it is important to develop practice to write the UI unit tests. There are many reasons for that and we are not going to go in that direction, so let's come to the point. In this blog, we are going to learn how to write unit test cases for AngularJS controllers with the help of Jasmine library. Prerequisites: AngularJS Some details regarding why we write unit test cases would help The example I have used uses Angular 1.2.11 and Jasmine 1.3.1. With minor changes, this should also work for the latest version of AngularJS, so you can just focus on the concepts. Other points to consider: For Jasmine 2.x, there are few changes in some methods. For example, for Jasmine 1.3, you would write spyOn(mockObj, ‘method’).andReturn(someReturnVal) The same thing for Jasmine 2.x, you would write as spyOn(mockObj, ‘method’).and.return(someReturnVal) Also, there are some changes/enhancement in 2.x, but as of no...