我正在使用角模拟注入我的控制器进行单元测试。我没有做到这一点,因为我一直得到以下错误。
[$injector:unpr] Unknown provider: PatientRecordsControllerProvider <- PatientRecordsController这是我的代码设置-
(function () {
angular.module('patient_profile', ['ngRoute']);
})();
(function () {
var PatientRecordsController = function () {
};
angular.module('patient_profile').controller('PatientRecordsController', PatientRecordsController);
})();还有我的测试用例
describe('PatientRecordsController:unit-testing', function () {
beforeEach(module('patient_profile'));
it('timeline should be an array', inject(['PatientRecordsController',
function (controller) {
//Cant do stuff
}
]));
});、UPDATE、--同样的过程在服务中运行得非常好。怎么会这样?
发布于 2014-04-14 14:08:49
控制器必须使用$controller服务实例化。下面的测试清洁器的格式不是吗?
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
});
});https://stackoverflow.com/questions/23061428
复制相似问题