How to mock a module in angular

后端 未结 2 1872
说谎
说谎 2021-01-18 05:18

So I\'ve read many posts but no suggestions as worked so far.

I am wanting to mock a module - say angular-foo. The original file is loaded along with everything else

2条回答
  •  情歌与酒
    2021-01-18 06:00

    What did the trick for me was putting the provider before the module declaration:

      beforeEach(module(function($provide) {
        $provide.provider('myProvider', function() {
          return {
            myProviderFunction: function() {},
    
            $get: function () {
              return {
                myProviderFunction: function() {}
              };
            }
          };
        });
      }));
    
      beforeEach(module('myApp'));
    

提交回复
热议问题