Skip to content
Browse files

async view spec for checking DOM elements

  • Loading branch information...
1 parent 774bc5f commit f09a996ad36651ee06736fff96538685092c0459 @larrymyers larrymyers committed Dec 19, 2011
Showing with 28 additions and 9 deletions.
  1. +1 −1 js/ext/backbone.localStorage.js
  2. +25 −8 js/koans/aboutViews.js
  3. +2 −0 specrunner.html
View
2 js/ext/backbone.localStorage.js
@@ -79,7 +79,7 @@ Backbone.sync = function(method, model, options, error) {
var store = Backbone.localStorageDB;
if (!store) {
- throw new Exception('No Store instance created for Backbone.localStorageDB');
+ throw new Error('No Store instance created for Backbone.localStorageDB');
}
switch (method) {
View
33 js/koans/aboutViews.js
@@ -2,25 +2,25 @@ describe('About Backbone.View', function() {
var todoView;
beforeEach(function() {
+ $('body').append('<ul id="todoList"></ul>');
todoView = new TodoView({ model: new Todo() });
});
afterEach(function() {
todoView.remove();
+ $('#todoList').remove();
});
- xit('Should be tied to a DOM element when created, based off the property provided.', function() {
+ it('Should be tied to a DOM element when created, based off the property provided.', function() {
expect(todoView.el.tagName.toLowerCase()).toBe('what html element tag name represents this view?');
});
- xit('Is backed by a model instance, which provides the data.', function() {
+ it('Is backed by a model instance, which provides the data.', function() {
expect(todoView.model).toBeDefined();
expect(todoView.model.get('done')).toBe("What's the value for Todo.get('done') here?");
});
- xit('Can render, after which the DOM representation of the view will be visible.', function() {
- $('body').append('<ul id="todoList"></ul>');
-
+ it('Can render, after which the DOM representation of the view will be visible.', function() {
todoView.render();
// Hint: render() just builds the DOM representation of the view, but doesn't insert it into the DOM.
@@ -30,11 +30,28 @@ describe('About Backbone.View', function() {
// Hint: http://documentcloud.github.com/backbone/#View-el
expect($('#todoList').find('li').length).toBe(1);
-
- $('#todoList').remove();
});
it('Can use an events hash to wire up view methods to DOM elements.', function() {
- // TODO example using TootApp view to show how to test events hash
+ var viewElt;
+
+ runs(function() {
+ $('#todoList').append(todoView.render().el);
+ });
+
+ waitsFor(function() {
+ viewElt = $('#todoList li input.check').filter(':first');
+
+ return viewElt.length > 0;
+ }, 1000, 'Expected DOM Elt to exist');
+
+ runs(function() {
+ // Hint: How would you trigger the view, via a DOM Event, to toggle the 'done' status.
+ // (See todos.js line 70, where the events hash is defined.)
+ //
+ // Hint: http://api.jquery.com/click
+
+ expect(todoView.model.get('done')).toBe(true);
+ });
});
});
View
2 specrunner.html
@@ -30,6 +30,8 @@
var reporter = new KoansReporter();
$(document).ready(function(evt) {
+ Backbone.localStorageDB = new Store('todosSpecs');
+
jasmine.getEnv().addReporter(reporter);
jasmine.getEnv().execute();
});

0 comments on commit f09a996

Please sign in to comment.
Something went wrong with that request. Please try again.