我已經得到了我的工作文件的copule,我試圖創建這種方法我有我的觀點骨幹骨幹聽衆似乎沒有被解僱
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)
我收到錯誤'錯誤:預計的間諜被調用一次,但被稱爲0次'任何人有任何想法,爲什麼事件沒有被觸發時,輸入被點擊?
在此先感謝。
'點擊()'用括號可能觸發事件? – Tallmaris