How can i test a AngularJS provider?

后端 未结 3 1108
孤城傲影
孤城傲影 2021-02-03 12:09

I need to test my own angular provider, and I need to test it in both config and run phase to check that config methods work and that the instantiated provider is indeed configu

3条回答
  •  不要未来只要你来
    2021-02-03 12:42

    It's actually a lot simpler than it would at first seem to test a provider in AngularJS:

    describe('Testing a provider', function() {
      var provider;
    
      beforeEach(module('plunker', function( myServiceProvider ) {
          provider = myServiceProvider;
      }));
    
      it('should return true on method call', inject(function () {
        expect( provider.method() ).toBeTruthy();
      }));
    });
    

    ```

    The proof is in the Plunker: http://plnkr.co/edit/UkltiSG8sW7ICb9YBZSH

提交回复
热议问题