Skip to content

Instantly share code, notes, and snippets.

@tatsuro-ueda
Created December 11, 2012 01:30
Show Gist options
  • Save tatsuro-ueda/4254988 to your computer and use it in GitHub Desktop.
Save tatsuro-ueda/4254988 to your computer and use it in GitHub Desktop.
Jasmine Async Test on CoffeeScript
# 「JS開発におけるTDDと自動テストツール利用の勘所 」より引用。
# http://www.slideshare.net/KojiNakamura/jstdd
it "should be async", ->
# 非同期処理ブロックはruns()で定義される
runs ->
expect(true).toBeTruthy()
# waits()で次のブロック実行を、指定したミリ秒間保留する
waits(500)
spy = jasmine.createSpy()
runs ->
setTimeout spy, 1000
# waitsFor()はコールバックがtrueを返すまで、次のブロック実行を保留する
waitsFor ->
spy.callCount > 0
runs ->
expect(true).toBeTruthy()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment