Note that there are some explanatory texts on larger screens.

plurals
  1. POtesting backbone.js view events with jasmine
    primarykey
    data
    text
    <p>I'm trying to implement view tests for a Coffeescript implementation of the ubiquitous backbone.js 'todo' example (see github.com/rsim/backbone_coffeescript_demo.)</p> <p>My jasmine tests of the above demo work pretty well, except for view events. I expect I am stuck on one or both of the following i) I do not understand the event binding in the view code, ii) I do not understand how to properly set up the Jasmine test of the view code events.</p> <p>Here is an example of the 'edit' event...</p> <pre><code>class TodoApp.TodoView extends Backbone.View tagName: "li" template: TodoApp.template '#item-template' events: "dblclick div.todo-content" : "edit" ... initialize: -&gt; _.bindAll this, 'render', 'close' @model.bind 'change', @render @model.bind 'destroy', =&gt; @remove() render: -&gt; $(@el).html @template @model.toJSON() @setContent() this edit: -&gt; $(@el).addClass "editing" @input.focus() ... </code></pre> <p>...now here's a test of whether focus was gained upon double clicking:</p> <pre><code> describe "edit state", -&gt; li = null beforeEach -&gt; setFixtures('&lt;ul id="todo-list"&gt;&lt;/ul&gt;') model = new Backbone.Model id: 1, content: todoValue, done: false view = new TodoApp.TodoView model: model, template: readFixtures("_item_template.html") $("ul#todo-list").append(view.render().el) li = $('ul#todo-list li:first') target = li.find('div.todo-content') expect(target).toExist() target.trigger('dblclick') # here's the event! it "input takes focus", -&gt; expect(li.find('.todo-input').is(':focus')).toBe(true) </code></pre> <p>The expectation on neither i) the spy nor ii) the focus is met.</p> <p>Is there a peculiarity to testing backbone.js event code about which I should be aware in Jasmine?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload