[英]Angularjs is not able to find my controller
I am using angular-mock to inject my controller for unit testing. 我正在使用angular-mock注入控制器以进行单元测试。 I am failing to do so since I keep getting the following error.
由于不断出现以下错误,因此我无法这样做。
[$injector:unpr] Unknown provider: PatientRecordsControllerProvider <- PatientRecordsController
Here is my code setup - 这是我的代码设置-
(function () {
angular.module('patient_profile', ['ngRoute']);
})();
(function () {
var PatientRecordsController = function () {
};
angular.module('patient_profile').controller('PatientRecordsController', PatientRecordsController);
})();
And my test case 还有我的测试用例
describe('PatientRecordsController:unit-testing', function () {
beforeEach(module('patient_profile'));
it('timeline should be an array', inject(['PatientRecordsController',
function (controller) {
//Cant do stuff
}
]));
});
UPDATE The same procedure works perfectly fine with services. 更新相同的过程可以很好地用于服务。 How come?
怎么会?
Controller has to be instantiated using $controller
service. 必须使用
$controller
服务实例化$controller
。 Isn't the below format of test cleaner? 以下格式的测试清洁器不是吗?
describe('PatientRecordsController:unit-testing', function () {
var controller;
beforeEach(function(){
module('patient_profile');
inject(function(_$controller_){
controller = _$controller_('PatientRecordsController', {});
});
});
it('timeline should be an array', function(){
//DO STUFF using controller
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.