Skip to content

Instantly share code, notes, and snippets.

@tatsuro-ueda
Created December 11, 2012 01:23
Show Gist options
  • Save tatsuro-ueda/4254956 to your computer and use it in GitHub Desktop.
Save tatsuro-ueda/4254956 to your computer and use it in GitHub Desktop.
Jasmine Spy on CoffeeScript
# 「JS開発におけるTDDと自動テストツール利用の勘所 」より引用。
# http://www.slideshare.net/KojiNakamura/jstdd
it "should be called", ->
obj =
method: ->
spyOn obj, "method" # spyOnメソッドでオブジェクトの特定メソッドをスパイ化
obj.method()
expect(obj.method).toHaveBeenCalled() # spy用のMatcherが用意されている
test "should be called", ->
spy = jasmine.createSpy() # スパイ化された関数オブジェクトを作成する
spy()
expect(spy).toHaveBeenCalled()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment