Permalink
Browse files

minor formatting changes, removing tests requiring more complex spies…

… (to be covered later)
  • Loading branch information...
addyosmani committed Feb 24, 2012
1 parent 0bb3c38 commit b776458d45f49b8e80dd330579b2d0e12a05be10
Showing with 271 additions and 306 deletions.
  1. +5 −1 js/ext/template.js
  2. +11 −16 js/koans/aboutApps.js
  3. +52 −57 js/koans/aboutCollections.js
  4. +121 −125 js/koans/aboutEvents.js
  5. +52 −55 js/koans/aboutModels.js
  6. +19 −48 js/koans/aboutViews.js
  7. +5 −0 js/todos.js
  8. +6 −4 specrunner.html
View
@@ -1,4 +1,5 @@
(function($) {
+
var cache = {};
function _render(elt, template, data, callback) {
@@ -9,6 +10,7 @@
elt.append(html);
callback();
}
+
/**
* Fetches the Underscore.js template at the given path,
@@ -30,7 +32,9 @@
cache[path] = _.template(data);
_render(self, cache[path], obj, callback);
});
-
+
return self;
};
+
+
})(jQuery);
View
@@ -1,7 +1,5 @@
-
module('About Backbone Applications', {
-
setup: function() {
Backbone.localStorageDB = new Store('testTodos');
$('#qunit-fixture').append('<div id="app"></div>');
@@ -12,20 +10,17 @@ module('About Backbone Applications', {
this.App.todos.reset();
$('#app').remove();
}
-
});
- test('Should bootstrap the application by initializing the Collection.', function() {
- expect(2);
- notEqual(this.App.todos, undefined);
- equal(this.App.todos.length, 0);
- });
-
- /*
- test('Should bind Collection events to View creation.', function() {
- $('#new-todo').val('Foo');
- $('#new-todo').trigger(new $.Event('keypress', { keyCode: 13 }));
- equal(this.App.todos.length, 1);
- });
+test('Should bootstrap the application by initializing the Collection.', function() {
+ expect(2);
+ notEqual(this.App.todos, undefined);
+ equal(this.App.todos.length, 0);
+});
+
-*/
+test('Should bind Collection events to View creation.', function() {
+ $('#new-todo').val('Foo');
+ $('#new-todo').trigger(new $.Event('keypress', { keyCode: 13 }));
+ equal(this.App.todos.length, 1);
+});
@@ -1,63 +1,58 @@
-
module('About Backbone.Collection');
- test('Can add Model instances as objects and arrays.', function() {
-
- expect(3);
-
- var todos = new TodoList();
-
- equal(todos.length, 0);
-
- todos.add({ text: 'Clean the kitchen' });
-
- console.log(todos);
-
- equal(todos.length, 1);
-
- todos.add([
- { text: 'Do the laundry', done: true },
- { text: 'Go to the gym'}
- ]);
-
- equal(todos.length, 3);
- });
-
- test('Can have a url property to define the basic url structure for all contained models.', function() {
- expect(1);
- var todos = new TodoList();
- equal(todos.url, '/todos/');
- });
-
- test('Fires custom named events when the models change.', function() {
-
- expect(2);
- var todos = new TodoList();
-
- var addModelCallback = function(){
- ok( true, 'add model callback called');
- start();
- }
-
- stop();
- todos.bind('add', addModelCallback);
-
- // How would you get the 'add' event to trigger?
- todos.add({text:"New todo"});
-
- var removeModelCallback = function(){
- ok( true, 'remove model callback called');
- start();
- }
-
- stop();
- todos.bind('remove', removeModelCallback);
-
- // How would you get the 'remove' callback to trigger?
- todos.remove(todos.last());
-
- });
+test('Can add Model instances as objects and arrays.', function() {
+
+ expect(3);
+
+ var todos = new TodoList();
+ equal(todos.length, 0);
+
+ todos.add({ text: 'Clean the kitchen' });
+ equal(todos.length, 1);
+
+ todos.add([
+ { text: 'Do the laundry', done: true },
+ { text: 'Go to the gym'}
+ ]);
+
+ equal(todos.length, 3);
+});
+
+test('Can have a url property to define the basic url structure for all contained models.', function() {
+ expect(1);
+ var todos = new TodoList();
+ equal(todos.url, '/todos/');
+});
+
+test('Fires custom named events when the models change.', function() {
+
+ expect(2);
+ var todos = new TodoList();
+
+ var addModelCallback = function(){
+ ok( true, 'add model callback called');
+ start();
+ }
+
+ stop();
+ todos.bind('add', addModelCallback);
+
+ // How would you get the 'add' event to trigger?
+ todos.add({text:"New todo"});
+
+ var removeModelCallback = function(){
+ ok( true, 'remove model callback called');
+ start();
+ }
+
+ stop();
+ todos.bind('remove', removeModelCallback);
+
+ // How would you get the 'remove' callback to trigger?
+ todos.remove(todos.last());
+
+});
Oops, something went wrong.

0 comments on commit b776458

Please sign in to comment.