我正在查看 TODO MVC AngularJS 示例,我看到应用程序被定义为一个模块。
var todomvc = angular.module('todomvc', []);
在控制器内部,我看到它们定义为:
todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, todoStorage, filterFilter) {
//...
});
我的问题涉及单元测试......我如何为该类编写单元测试?
我试过这样的事情:
describe('TodoCtrl', function () {
var controller;
beforeEach(function () {
controller = todomvc.TodoCtrl;
});
afterEach(function() {
controller = null;
});
describe('addTodo() method', function() {
console.log(controller)
it('should do something', function () {
expect(typeof controller.addTodo).toBe(true); //should fail
});
});
});
...但随后“控制器”最终为空或未定义。
我是否需要修改 TODO MVC 应用程序以使传递给todomvc.controller()的函数不是匿名的?
任何方向都会受到赞赏,因为我对 Angular 很陌生。