Skip to content

Instantly share code, notes, and snippets.

@gmoeck
Created January 10, 2011 18:21
Show Gist options
  • Save gmoeck/773180 to your computer and use it in GitHub Desktop.
Save gmoeck/773180 to your computer and use it in GitHub Desktop.
var controller, stubbedFunction;
module("Todos.tasksController", {
setup: function() {
controller = Todos.tasksController;
},
teardown: function() {
SC.RunLoop.begin();
Todos.store.reset();
SC.RunLoop.end();
}
});
test("#countSummary - when there are no tasks", function() {
stubbedFunction = controller.get;
controller.get = CoreTest.stub('length', {action: function() { return 0;} });
equals(controller.countSummary(), 'No Tasks', 'returns "No Tasks"');
controller.get = stubbedFunction;
});
test("#countSummary - when there is one task", function() {
stubbedFunction = controller.get;
controller.get = CoreTest.stub('length', {action: function() { return 1;} });
equals(controller.countSummary(), '1 Task', 'returns "1 Task"');
controller.get = stubbedFunction;
});
test("#countSummary - when there is more than one task", function() {
stubbedFunction = controller.get;
controller.get = CoreTest.stub('length', {action: function() { return 2;} });
equals(controller.countSummary(), '2 Tasks', 'returns "n Tasks" where n is the number of tasks');
controller.get = stubbedFunction;
});
//ADDED THIS TEST
test('#addTask - creates a new task', function() {
var mockedFunction = Todos.store.createRecord;
var createMockObject = CoreTest.stub('createTask', function() {return YES;});
Todos.store.createRecord = createMockObject;
controller.addTask();
equals(createMockObject.callCount, 1, 'Delegates to the store to create the record');
Todos.store.createRecord = mockedFunction;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment