简体   繁体   English

测试工厂时未知的提供者

[英]Unknown provider when testing factory

I'm getting the following error when trying to test a factory in angualar: 尝试在angualar中测试工厂时出现以下错误:

Error: [$injector:unpr] Unknown provider: $resourceProvider <- $resource <- myService 错误:[$ injector:unpr]未知提供程序:$ resourceProvider <-$ resource <-myService

There are already tests in the project that do similar things and they work fine, so I can't for the life of me figure out why these don't work. 项目中已经有测试可以完成类似的工作,并且可以正常工作,所以我无法一生找出这些测试为什么不起作用。 Here is the impl code: 这是impl代码:

(function () {
'use strict';

var module = angular.module('first.module', []);

function firstThing() {
    this.doSomething = function (something) {
        return campaign;
    };
}

module.service('firstThing', firstThing);

function myServiceFactory($resource, notifier) {
    var Resource = $resource('/api/campaigns/:id', { id: '@id' }, {
        get: { method: 'GET' }
    });

    function listItems() {
        return [];
    }

    return {
        list: listItems
    };
}

module.factory('myService', myServiceFactory);

})();

The test code is: 测试代码为:

'use strict';

describe('My service test', function () {

    var myServiceFactory, campaign, $injector;

    beforeEach(module('first.module'));

    beforeEach(inject(function (_$injector_) {
        $injector = _$injector_;
        myServiceFactory = $injector.get('myService');
    }));

    it('true is true', function () {
        expect(true).toEqual(true);
    });
});

Karma is being used for the tests. 业力被用于测试。 Thanks for any help. 谢谢你的帮助。

您应该将ngResource模块添加到模块依赖项中。

var module = angular.module('first.module', ['ngResource']);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM