Unit-testing Angular services and directives

Being new to Angular (and to tell the truth, JS itself) I'm strugling with isolated unit-testing of services and directives. I tried to compile solution from different examples found in the internet, but failed.

I've got a service:

angular.module('myApp.services', [])
.factory('autoCmpltDataSvc', function ($http) {
    return {
        source: function (request, response) {
            $http({
                method: 'jsonp',
                url: 'http://ws.geonames.org/searchJSON?callback=JSON_CALLBACK',
                params: {
                    featureClass: "P",
                    style: "full",
                    maxRows: 12,
                    name_startsWith: request.term
                }
            }).success(function (data, status) {
                response($.map(data.geonames, function (item) {
                    return {
                        label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
                        value: item.name,
                        geonameId: item.geonameId
                    }
                }));
            });
        }
    }
});

I'd like to fake the interaction with actual web service passing predefined array and check that it returns correct response when passing different values for request.term.

The other task is to unit-test a directive (wrapper around jquery autocomplete)

angular.module('myApp.directives', [])
.directive('autocomplete', function (autoCmpltDataSvc) {
      return {
          restrict: 'E',
          replace: true,
          transclude: true,
          template: '<input id="DstnSlctr" ng-model="autocomplete" type="text"/>',
          link: function (scope, element, attrs) {
              scope.$watch(autoCmpltDataSvc, function () {
                  element.autocomplete({
                      source: autoCmpltDataSvc.source,
                      select: function (event, ui) {
                          scope[attrs.selection] = ui.item.value;
                          scope[attrs.selectionid] = ui.item.geonameId;
                          scope.$apply();
                      }
                  });
              });
          }
      }
  });

I'd like to fake the call to the service with some predefined array and check that the scope is modified correctly.

Is it possible to test those in isolation or should I use only e2e tests for this task?

Thanks in advance for responses! Ksenia

For the service, essentially what you will want to do is use $httpBackend in your unit test. What angular does is it has an $httpBackend that it uses (behind $http). But when you are injecting it into a unit test, it magically knows and intercepts the calls.

Per doc, what you need to do is stage your http requests by providing real urls (and what params you will pass in unit test), in beforeEach and also add an afterEach. NOTE: I believe doc has a typo

var $http; //  and should probably be: var $httpBackend

For directives, it depends. If you've created the entire directive, then unit testing is probably a much easier road. When wrapping plugins, then you might consider a couple of things. Firstly, write e2e tests may be a good first step. Secondly, see if your own code (in the directive) could be put into a helper method and that part may be unit testable.