Skip to content

Instantly share code, notes, and snippets.

@kalebdf
Created August 3, 2012 21:03
Show Gist options
  • Save kalebdf/3251500 to your computer and use it in GitHub Desktop.
Save kalebdf/3251500 to your computer and use it in GitHub Desktop.
Event triggered on helper for async Jasmine calls
###
Stellar Module Test - Assumes jasmine is global
@author: Kaleb Fulgham
@license: MIT
###
define [
'../specs/helpers/TestHelpers'
'modules/StellarModule'
],
(TestHelpers, StellarModule) ->
describe "StellarModule", ->
describe "ItemView", ->
it "should do foo bar baz with view", ->
itemView = new ItemView()
# Expect event 'render' to be triggered on the item view
TestHelpers.eventTriggeredOn itemView, 'render', =>
$a = itemView.$('a')
expect($a.data('id')).toEqual @flight.id, 'Anchor data ID attribute'
# more expectations
# Call the async code
itemView.render()
###
TestHelpers
@author: Kaleb Fulgham
@license: MIT
###
define [], ->
TestHelpers =
eventTriggeredOn: (caller, eventName, callback) ->
###
Wait for the event to be triggered and execute the callback once done.
###
spy = spyOn(caller, 'trigger')
waitsFor ->
result = false
if spy.callCount > 0
for callArgs in spy.argsForCall
if callArgs[0] == eventName
result = true
break
result
, "Async call to trigger event [#{eventName}] never occurred", 1000
runs ->
callback()
TestHelpers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment