Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teejayvanslyke/2152540 to your computer and use it in GitHub Desktop.
Save teejayvanslyke/2152540 to your computer and use it in GitHub Desktop.
Jasmine matcher for Backbone.Event expectations
# 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