Skip to content

Instantly share code, notes, and snippets.

@kalebdf
Created July 19, 2012 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kalebdf/3145434 to your computer and use it in GitHub Desktop.
Save kalebdf/3145434 to your computer and use it in GitHub Desktop.
Check deferred helper (promises) for 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()
promise = itemView.render()
TestHelpers.checkDeferred promise, ->
expect(itemView.$el).toBeDefined();
# more expectations
###
TestHelpers
@author: Kaleb Fulgham
@license: MIT
###
define [], ->
TestHelpers =
checkDeferred: (df, callback) ->
###
Wait for the deferred object to finish and execute the callback once done.
###
spy = jasmine.createSpy()
df.then(spy)
waitsFor ->
spy.callCount > 0
, "Async call never occurred", 1000
runs ->
callback.apply @, spy.mostRecentCall.args if callback
TestHelpers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment