Created
April 25, 2012 15:51
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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