作業中のファイルのコプルがあり、バックボーン ビューにあるこのメソッドでリスナーを作成しようとしています。
appView.js.coffee
namespace "happiness_kpi", (exports) ->
exports.appView = Backbone.View.extend
events:
"click #happy" : "selection"
selection: ->
console.log "selection was called"
index.html.haml
%input{ :type => "image", :src => "/assets/smiley.jpg", :alt => "happy", :id => "happy" }
%input{ :type => "image", :src => "/assets/undecided.jpg", :alt => "undecided", :id => "undecided" }
%input{ :type => "image", :src => "/assets/sad.jpg", :alt => "sad", :id => "sad" }
ここに私の仕様があります:
app_view_spec.js.coffee
it "is called when one of the faces is clicked", ->
$("body").append('<input alt="happy" id="happy" src="/assets/smiley.jpg" type="image">')
$("body").append('<input alt="undecided" id="undecided" src="/assets/undecided.jpg" type="image">')
$("body").append('<input alt="sad" id="sad" src="/assets/sad.jpg" type="image">')
@subject.selection = sinon.spy()
$("#happy").click
sinon.assert.calledOnce(@subject.selection)
「エラー: スパイが 1 回呼び出されると予想されていましたが、0 回呼び出されました」というエラーが表示されます。
前もって感謝します。