我正在使用角度1.6。目前开始进行单元测试。 这是我的控制器
angular.module('myModule').controller('MyCtrlr', MyCtrlr);
function MyCtrlr($scope, $mdDialog, ajaxCall) {
this.mode = 'Hello';
}
这是我的测试文件。
describe('Controllers', function() {
var $controller, $rootScope;
beforeEach(module('myModule'));
beforeEach(inject(function(_$controller_, _$rootScope_){
$controller = _$controller_;
$rootScope = _$rootScope_;
}));
describe('Mode should be Hello', function() {
it('Should be Hello', function() {
var $scope = $rootScope.$new();
var controller = $controller('MyCtrlr', { $scope: $scope});
expect(controller.mode).toBe('Hello');
});
});
});
我无法删除$ mdDialog和ajaxCall,因为稍后需要在此控制器中使用它们。
我的问题是当我开始测试它引发错误时
Error: [$injector:unpr] Unknown provider: $mdDialogProvider <- $mdDialog <- MerchantController
https://errors.angularjs.org/1.7.5/$injector/unpr?p0=%24mdDialogProvider%20%3C-%20%24mdDialog%20%3C-%20MerchantController in bower_components/angular/angular.js (line 4905)
bower_components/angular/angular.js:4905:86
getService@bower_components/angular/angular.js:5065:39
bower_components/angular/angular.js:4910:48
getService@bower_components/angular/angular.js:5065:39
injectionArgs@bower_components/angular/angular.js:5090:68
instantiate@bower_components/angular/angular.js:5134:31
$controller@bower_components/angular/angular.js:11688:39
bower_components/angular-mocks/angular-mocks.js:2555:23
test/blacklistMerchantsTest.js:12:41
<Jasmine>
如果有人帮我解决这个问题会很有帮助。