user2167582
user2167582

Reputation: 6368

in angular web application what needs to be unit tested?

for a front-end developer, who writes angular code, what part of a javascript front-end project should I be unit testing? I find it needless to test a lot of the code, and my biggest hang up is which part of the angular services needs to be tested? if $httpBackend is a mock call, what's the point of calling it?

Upvotes: 0

Views: 72

Answers (1)

Davin Tryon
Davin Tryon

Reputation: 67296

As your project grows in complexity, you may find that your angular application is doing a lot. Angular's design allows the client to take a lot of the responsibility for processing and rendering data from the server.

Yes, I agree, you shouldn't test anything but your own code. So, writing tests for $http is useless. However, if you are expecting the server to return a specific JSON contract, and you want the assurance that you are mapping that correctly to a structure that you will use in your angular app, that is worth testing. Further, if you are making calculations in services or controllers, that logic is worth testing.

Angular itself is set up to support TDD because it has a nice separation of concerns between the view, controller and services (even directives can be compiled and tested). All of the javascript code that you write is a good candidate for test coverage. So, IMHO, you should be unit testing your directives, your controllers, and your services. You can get as detailed as you want to give yourself the assurance that your code is solid.

Upvotes: 1

Related Questions