Title / Description
Code describe "ToDoApp.Views.TodoCollectionView", -> describe "rendering", -> describe "when there is a collection", -> it "renders the collection", -> collection = new ToDoApp.Collections.TodosCollection([ {id: 1, title: 'make example test', done: false} {id: 2, title: 'make example work', done: false} ]) view = new ToDoApp.Views.TodoCollectionView(collection: collection) setFixtures(view.render().$el) expect(view.children.length).toEqual(2) describe "when there is not a collection", -> it "renders the collection", -> collection = new ToDoApp.Collections.TodosCollection([]) view = new ToDoApp.Views.TodoCollectionView(collection: collection) setFixtures(view.render().$el) expect(view.children.length).toEqual(0) describe "events", -> describe "click .add", -> it "adds a new model to the collection", -> view = new ToDoApp.Views.TodoCollectionView(collection: new ToDoApp.Collections.TodosCollection()) setFixtures(view.render().$el) $('.add').click() expect(view.collection.length).toEqual(1) it "sets the new model's title from the text field", -> view = new ToDoApp.Views.TodoCollectionView(collection: new ToDoApp.Collections.TodosCollection()) setFixtures(view.render().$el) $('#new-todo').val("This is new") $('.add').click() expect(view.collection.models[0].get("title")).toEqual("This is new") it "clears the value in the text field", -> view = new ToDoApp.Views.TodoCollectionView(collection: new ToDoApp.Collections.TodosCollection()) setFixtures(view.render().$el) $('#new-todo').val("This will be cleared") $('.add').click() expect($('#new-todo').val()).toEqual("") When we run these tests (on the command line, for ease of copy + paste) we get: Run all Jasmine suites Run Jasmine suite at http://localhost:57702/jasmine Finished in 0.009 seconds ToDoApp.Views.TodoCollectionView rendering when there is a collection ✘ renders the collection ➤ TypeError: 'undefined' is not a constructor (evaluating 'new ToDoApp.Views.TodoCollectionView({ > [#] collection: collection > [#] })') in http://localhost:57702/assets/spec.js (line 16416) when there is not a collection ✘ renders the collection ➤ TypeError: 'undefined' is not a constructor (evaluating 'new ToDoApp.Views.TodoCollectionView({ > [#] collection: collection > [#] })') in http://localhost:57702/assets/spec.js (line 16427) events click .add ✘ adds a new model to the collection ➤ TypeError: 'undefined' is not a constructor (evaluating 'new ToDoApp.Views.TodoCollectionView({ > [#] collection: new ToDoApp.Collections.TodosCollection() > [#] })') in http://localhost:57702/assets/spec.js (line 16439) ✘ sets the new model's title from the text field ➤ TypeError: 'undefined' is not a constructor (evaluating 'new ToDoApp.Views.TodoCollectionView({ > [#] collection: new ToDoApp.Collections.TodosCollection() > [#] })') in http://localhost:57702/assets/spec.js (line 16448) ✘ clears the value in the text field ➤ TypeError: 'undefined' is not a constructor (evaluating 'new ToDoApp.Views.TodoCollectionView({ > [#] collection: new ToDoApp.Collections.TodosCollection() > [#] })') in http://localhost:57702/assets/spec.js (line 16458) 5 specs, 5 failures Done. Guard::Jasmine stops server. rake aborted! Some specs have failed
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code