2016-04-29 128 views
0

我已经叫服务称为“泛函”功能ServiceA也许还可以利用在服务中定义一个函数在另一个控制器:如何angularjs单元测试

return Restangular 
    .extendModel('modelA', function(model) { 
      model.functionA = function(body) { 
       return this.customPUT(body, 'add') 
      }; 
      return model; 
    }) 
    .service('accounts'); 

我还可以ControllerB使用它,它工作得很好。

function functionB(body){ 
    instanceModelB.instanceModelA.functionA(body) 
      .then(onSuccess) 
      .catch(onFail) 
      .finally(onFinally); 
} 

但是如何在ControllerB的单元测试中使用它?我的意思是如何在ControllerB的单元测试中调用functionA?它总是说'功能A不是功能'。 在此先感谢。

回答

0

对我来说,听起来像你serviceA.functionA()不是全局访问。

您可能只需要导出您的serviceA,然后您应该能够全局访问它。