どこにでもある backbone.js の「todo」サンプルの Coffeescript 実装のビュー テストを実装しようとしています (github.com/rsim/backbone_coffeescript_demo を参照してください)。
上記のデモのジャスミン テストは、ビュー イベントを除いて、かなりうまく機能します。次のいずれかまたは両方で行き詰まっていると思います。i) ビュー コードのイベント バインディングがわかりません。ii) ビュー コード イベントの Jasmine テストを適切に設定する方法がわかりません。
「編集」イベントの例を次に示します...
class TodoApp.TodoView extends Backbone.View
tagName: "li"
template: TodoApp.template '#item-template'
events:
"dblclick div.todo-content" : "edit"
...
initialize: ->
_.bindAll this, 'render', 'close'
@model.bind 'change', @render
@model.bind 'destroy', => @remove()
render: ->
$(@el).html @template @model.toJSON()
@setContent()
this
edit: ->
$(@el).addClass "editing"
@input.focus()
...
...ここで、ダブルクリックでフォーカスが得られたかどうかをテストします:
describe "edit state", ->
li = null
beforeEach ->
setFixtures('<ul id="todo-list"></ul>')
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", ->
expect(li.find('.todo-input').is(':focus')).toBe(true)
i) スパイも ii) 焦点も当てはまらない。
Jasmine で注意すべき backbone.js イベント コードのテストに特殊性はありますか?