0

is it necessary that we mock $http service in angular js in order to write a unit test? if yes why should we do it? else could you let me know how to write a unit test without mocking $http service..

Venkat
  • 62
  • 8
  • Only if you're going to be testing functionality that uses the $http service. Don't mock what you don't need. – Tim May 14 '14 at 13:32
  • Hey Tim, if you don't mind, could you be more specific about your comment. I am writing a unit test for a controller which hits a server and get some data back so for this scenario should I mock $http? Thanq – Venkat May 14 '14 at 13:35
  • I don't see how I can be more specific. What don't you get? – Tim May 14 '14 at 13:38
  • lets say if i call a method in controller which is intern calling a service should i create a mock for $http as scenario or let the service hit server and get data..!? (What is the better way to do it?) – Venkat May 14 '14 at 13:52
  • Ah no, in that case you should mock the service – Tim May 15 '14 at 06:02
  • In my case instead I want to test a directive and that directive has a templateUrl property. I consider the directive and it's template as a single unit, but I'm not able to get rid of this problem. http://stackoverflow.com/questions/19320302/angular-testing-using-passthrough-in-unit-testing – Plap Jun 24 '14 at 20:02

0 Answers0