Skip to content

Instantly share code, notes, and snippets.

@EndangeredMassa
Created April 25, 2012 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EndangeredMassa/2490812 to your computer and use it in GitHub Desktop.
Save EndangeredMassa/2490812 to your computer and use it in GitHub Desktop.
Trying to get Zepto to trigger backbone events without attaching to the DOM
# using coffeescript and jasmine, but the idea should be clear
# if this runs on jquery, all tests pass; if it runs on zepto (RC1 or 0.8), only the second spec passes
it 'fails: triggers event on nested element', ->
$div = $('<div><div class="close"></div></div>')
notified = false
$div.on 'click', ->
notified = true
$div.find('.close').trigger('click')
waitsFor -> notified
it 'works: triggers event on element', ->
$div = $('<div></div>')
notified = false
$div.on 'click', ->
notified = true
$div.trigger('click')
waitsFor -> notified
it 'fails: triggers backbone event on unattached dom elements'
TestView = Backbone.View.extend
events:
'click .close': 'closeHandler'
closeHandler: ->
console.log 'in close handler'
@hide()
hide: ->
console.log 'in hide method'
@$el.remove()
render: ->
@$el.append('<div class="close"></div>')
view = new TestView
view.render()
# uncomment this line to make it work, but I don't want to attach it to the DOM if I don't have to
# @$jasmineContent.append(view.el)
spy = spyOn(view, 'hide')
view.$el.find('.close').trigger('click')
waitsFor -> spy.wasCalled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment