Created
November 18, 2011 23:40
-
-
Save searls/1378113 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#1 | |
doStuff = -> alert("Stuff!") | |
$('.do-stuff').live 'click', (e) -> | |
doStuff() | |
#2 | |
clickeyDo = (selector, callback) -> | |
$(selector).live 'click', (e) -> | |
e.preventDefault() | |
callback(e) |
This file contains hidden or 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
describe "#1 automatic binding, real trigger", -> | |
Given -> spyOn(window, "doStuff") | |
Given -> @$button = inject('do-stuff') | |
When -> @$button.trigger('click') | |
Then -> expect(doStuff).toHaveBeenCalled() | |
describe "#2 named function, spying, no trigger", -> | |
Given -> @$saveStuff = inject('save-stuff') | |
Given -> spyOn($.fn,"live") | |
Given -> @callback = jasmine.createSpy() | |
When -> clickeyDo('.save-stuff', @callback) | |
Then -> expect($.fn.live).toHaveBeenCalledWith('click', jasmine.any(Function)) | |
Then -> expect($.fn.live.mostRecentCall.object).toBe(@$saveStuff) | |
describe "~ the anonymous bound method", -> | |
Given -> @event = jasmine.createSpyObj('event',['preventDefault']) | |
When -> $.fn.live.mostRecentCall.args[1](@event) | |
Then -> expect(@event.preventDefault).toHaveBeenCalled() | |
Then -> expect(@callback).toHaveBeenCalledWith(@event) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment