Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在AngularJs&;中模拟$resourceProvider;茉莉花_Angularjs_Unit Testing_Jasmine - Fatal编程技术网

在AngularJs&;中模拟$resourceProvider;茉莉花

在AngularJs&;中模拟$resourceProvider;茉莉花,angularjs,unit-testing,jasmine,Angularjs,Unit Testing,Jasmine,在我的控制器中,我使用$resource:ng.resource.IResourceService可以帮助我从服务器获取数据 controllers.controller("testController", [ "$scope", "$resource", "$rootScope", "$http", "$window", "$location", "resourceService", function ($scope, $resource

在我的控制器中,我使用$resource:ng.resource.IResourceService可以帮助我从服务器获取数据

    controllers.controller("testController", [
        "$scope", "$resource", "$rootScope", "$http",
        "$window", "$location", "resourceService",
        function ($scope, $resource: ng.resource.IResourceService, $rootScope: IRootScope, 
                  $http, $window, $location, resourceService: services.IResourceService) {    ...//implementation
    }]);
这是我对Jasmine单元测试的尝试。然而,我越来越
错误:[$injector:unpr]未知提供程序:$resourceProvider为什么需要模拟
$resource
?您应该只模拟来自
$http
的数据;你好像已经在做了

    describe("testController Tests", function (): void {
        var vm: createDailylog.IViewModel;
        var $scope: ng.IScope;
        var $rootScope;
        var $httpBackend: ng.IHttpBackendService;
        //var $injector = angular.injector(['ng', 'ngResource']);
        var $resource = $injector.get('$resource');

        beforeEach(function (): void {
            module("controllers");
        });

        beforeEach(inject(function (_$controller_: ng.IControllerService,
            _$httpBackend_, _$resource_, _$rootScope_: IRootScope, $injector) {

            $httpBackend = _$httpBackend_;
            //$resource = _$resource_;

            this.$httpBackend = $httpBackend; 

            $rootScope = _$rootScope_.$new();

            $rootScope.config = {
                serverUrl: "https://test.domainName.net/",
                serverVersion: "test", 
                title: "Test Server Reference"
            };


            //instantiating controller
            vm = _$controller_('testController', {
                $scope: $scope,
                $resource: $injector.get("$resource"),
                $rootScope: _$rootScope_,
                $window: {},
                $location: {}
            });
        }));

        //afterEach(function () {
        //    $httpBackend.verifyNoOutstandingExpectation();
        //    $httpBackend.verifyNoOutstandingRequest();
        //}); 

        describe('when populate method is called', function () {

            it("should create controller!", function () {

                $httpBackend.flush();
                expect(true).toBe(true);
            });
        });

       );
    });
});