use*_*878 13 jasmine angularjs
我收到此错误:"错误:[$ injector:unpr]未知提供者:$ provideProvider < - $ provide".我被困了几个小时谷歌搜索.我已经看到很多这样做的例子,我不知道该怎么做.
"use strict";
describe('Controller: ProfileCtrl', function ($provide) {
//load the controller's module
var mockProfileFactory;
beforeEach(function() {
module('profileUpdate', function($provide) {
mockProfileFactory = {
get: function() {
id: 16
}
};
$provide.value('Profile', mockProfileFactory);
});
var ProfileCtrl;
var scope;
inject(function ($controller, $rootScope, $provide) {
scope = $rootScope.$new();
ProfileCtrl = $controller('ProfileCtrl', {
$scope: scope
});
});
});
it('should have 3 items', function() {
var things = scope.range(1,3,1);
expect(things).toBe(3);
});
Run Code Online (Sandbox Code Playgroud)
});
Pet*_*ell 17
你有一些奖金提供.特别是注入语句中的那个.你不能注入提供,它只适用于模块.请尝试以下更改.
"use strict";
// SEE no provide here
describe('Controller: ProfileCtrl', function () {
//load the controller's module
var mockProfileFactory;
beforeEach(function() {
module('profileUpdate', function($provide) {
mockProfileFactory = {
get: function() {
id: 16
}
};
$provide.value('Profile', mockProfileFactory);
});
var ProfileCtrl;
var scope;
// SEE and neither in the inject here
inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
ProfileCtrl = $controller('ProfileCtrl', {
$scope: scope
});
});
});
it('should have 3 items', function() {
var things = scope.range(1,3,1);
expect(things).toBe(3);
});
Run Code Online (Sandbox Code Playgroud)
});
阅读有关提供程序的angularjs概念的内容,并根据本指南检查代码:
| 归档时间: |
|
| 查看次数: |
8165 次 |
| 最近记录: |