Failing unit test of factory with dependency in AngularJS using Jasmine & Karma

穿精又带淫゛_ 提交于 2019-12-01 21:05:22

In the code you gave you have 2 typos, but I guess this isn't your real code:

  • Test Code, line 4:

    beforeEach(module('MyApp.Module'));
    

    should be:

    beforeEach(module('myApp.Module'));
    
  • And line 13, you forgot a quote at: return 'test';

As the error you get is "TestThisServiceProvider...", I would use $injector in a beforeEach to inject your service to test. Just after the second beforeEach(module(function(){...});

beforeEach(inject(function($injector) {
    myService = $injector.get('TestThisService');
}));

I think $injector take care of the dependencies (like ngResource in your case).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!