我的测试失败了,因为它说我的控制器没有定义。很奇怪,我认为我做的一切都很正确。
describe('homeCtrl', function() {
var httpBackend, controller, scope;
beforeEach(module('App'));
beforeEach(inject(function($httpBackend, $controller) {
scope = {};
httpBackend = $httpBackend;
controller = $controller('homeCtrl', { $scope: scope });
}));
it('should exist', function() {
expect(controller).toBeDefined();
});
});
我有我的home.js,这是像这样的控制器
var App = angular.module('App')
App.controller('homeCtrl', function($scope) {
})
错误为Expected undefined to be defined.
答案 0 :(得分:1)
您的 home.js
应该在模块中注入依赖项,将其更改为
var App = angular.module('App',[])
App.controller('homeCtrl', function($scope) {
})