Created
March 21, 2012 20:26
-
-
Save teejayvanslyke/2152540 to your computer and use it in GitHub Desktop.
Jasmine matcher for Backbone.Event expectations
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
# Usage: | |
# | |
# @model.doSomething = -> | |
# @other_model.trigger('something_done', 'somearg') | |
# | |
# expect(=> @model.doSomething()).toTrigger('something_done', on: @other_model, with: [ 'somearg' ]) | |
# | |
beforeEach -> | |
@addMatchers | |
toTrigger: (eventName, object) -> | |
block = @actual | |
args = object.with or [] | |
object = object.on or object | |
triggered = false | |
object.on eventName, (actualArgs...) -> | |
_(args).each (arg, index) -> | |
expect(actualArgs[index]).toEqual(arg) | |
triggered = true | |
block.apply() | |
return triggered |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment