It should also be noted that AngularJS and Node.js are more heavily favored by developers. Spring and Django seem to gaining popularity with employers and developers alike but not quite as much as React. Visit HackerRank for the full breakdown.
Until recently, the front-end testing I’d done had not directly tested any Angular services. In almost every case, the $http calls in the services were just returning data from an API back to a controller. However, on a recent project I had a scenario where the data from the API had to have some filtering and permission logic applied before passing on the data. This was a case where unit testing the service made sense.
As it turns out, testing a service is very similar to testing a controller in terms of setting up the test, injecting dependencies, and making assertions. The only real difference is the need to mock the $http call in the service. To do this the angular-mocks library provides the $httpBackend tool. Let’s walk through an example of testing a service.
One of the features of Angular is that it was built with testability in mind. The separation of the DOM layer, controllers, and services, as well as the use of dependency injection make it relatively easy to develop testable code.
I am very familiar with the practice of writing unit tests and have been testing C# code for several years. Although I did find testing in Angular to be a little confusing at first, once I got used to the code required to set-up the tests – it was pretty easy.