0
我试图在角度js中创建一个“待办事项列表”。完成任务后,我希望能够点击复选框标记完成。虽然它正在处理index.html,但我无法通过测试。无法获得业力测试传递到控制器上
这是我的测试:
describe('ToDoListController', function() {
beforeEach(module('ToDoList'));
var ctrl;
beforeEach(inject(function($controller) {
ctrl = $controller('ToDoListController');
}));
it('initialises with an empty list and term', function() {
expect(ctrl.listDisplay).toEqual([]);
expect(ctrl.taskTerm).toBeUndefined();
});
describe('when viewing the to do list', function(){
it('displays list items', function() {
ctrl.taskTerm = "hello";
ctrl.addTask();
expect(ctrl.listDisplay[0].task).toBe("hello");
});
it('is completed when clicked', function() {
ctrl.taskTerm = "hello";
ctrl.addTask();
ctrl.isCompleted("hello");
expect(ctrl.listDisplay[0].completed).toBe(true)
});
});
});
,这是我的控制器:
toDoList.controller('ToDoListController', [function() {
var self = this;
self.listDisplay = []
self.addTask = function() {
self.listDisplay.push({task: self.taskTerm, completed: false})
};
self.isCompleted = function(item) {
var i = self.listDisplay.indexOf(item)
self.listDisplay[i].completed = true
}
}]);
错误我得到的回复是:
TypeError: Cannot set property 'completed' of undefined
at self.isCompleted (/Users/edobrien/Documents/Projects/todo_challenge/js/toDoListController.js:13:35)
at Object.<anonymous> (/Users/edobrien/Documents/Projects/todo_challenge/test/toDoListController.spec.js:26:12)
仅供参考,错误发生在“ctrl.isCompleted(”hello“);”行
任何帮助你们可以给予将不胜感激!
我现在越来越\t类型错误:无法读取的未定义的属性“的forEach”,是有什么我失踪? – Munded
有一个错字,我写了ListDisplay而不是lisDisplay ...更新它......并且你不应该只是C&P代码! ; P –
哈哈对不起,我只是看看它是否有效! ListDisplay是正确的数组,我很困惑什么你askign更正 – Munded