How do I test an AngularJS service with Jasmine?

后端 未结 4 584
长发绾君心
长发绾君心 2020-12-04 06:37

(There is a related question here: Jasmine test does not see AngularJS module)

I just want to test a service without bootstrapping Angular.

I have look at so

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-04 07:03

    I needed to test a directive that required another directive, Google Places Autocomplete, I was debating on whether I should just mock it... anyway this worked with out throwing any errors for the directive that required gPlacesAutocomplete.

    describe('Test directives:', function() {
        beforeEach(module(...));
        beforeEach(module(...));
        beforeEach(function() {
            angular.module('google.places', [])
            .directive('gPlacesAutocomplete',function() {
                return {
                    require: ['ngModel'],
                    restrict: 'A',
                    scope:{},
                    controller: function() { return {}; }
                 };
            });
         });
         beforeEach(module('google.places'));
    });
    

提交回复
热议问题