我已经得到了我的工作文件的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