在AngularJs&;中模拟$resourceProvider;茉莉花
在我的控制器中,我使用$resource:ng.resource.IResourceService可以帮助我从服务器获取数据在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
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);
});
});
);
});
});