Skip to content

Instantly share code, notes, and snippets.

@searls
Created November 18, 2011 21:25
Show Gist options
  • Save searls/1377803 to your computer and use it in GitHub Desktop.
Save searls/1377803 to your computer and use it in GitHub Desktop.
mainWidget =
show: -> "Pretend this shows main widget"
login = ->
$.ajax
success: (response) ->
mainWidget.show() unless response == "fail"
beforeEach ->
jasmine.Spy.prototype.mostRecentConfig = ->
this.mostRecentCall.args[0]
describe "#login", ->
beforeEach ->
spyOn($,"ajax")
login("davemo", "password123")
describe "~ the success callback", ->
beforeEach -> spyOn(mainWidget,"show")
context "correct login info", ->
beforeEach ->
$.ajax.mostRecentConfig()['success']("win")
it "shows the main widget", ->
expect(mainWidget.show).toHaveBeenCalled()
context "incorrect login info", ->
beforeEach ->
$.ajax.mostRecentConfig()['success']("fail")
it "does not show main widget", ->
expect(mainWidget.show).not.toHaveBeenCalled()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment