-
-
Save ekdevdes/2473413 to your computer and use it in GitHub Desktop.
A simple Jasmine Ajax spying example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| window.context = window.describe | |
| describe ".googlePandaStatus", -> | |
| Given -> @ajaxCaptor = jasmine.captor() | |
| Given -> spyOn($, "get") | |
| When -> googlePandaStatus("Happy") | |
| And -> expect($.get).toHaveBeenCalledWith("http://google.com", @ajaxCaptor.capture()) | |
| describe "~ the AJAX success handler", -> | |
| Given -> spyOn(window, "printMessage") | |
| context "a Chinese panda", -> | |
| When -> @ajaxCaptor.value("Chinese") | |
| Then -> expect(printMessage).toHaveBeenCalledWith("Happy Chinese Panda") | |
| context "a Columbus Zoo panda", -> | |
| When -> @ajaxCaptor.value("Columbus Zoo") | |
| Then -> expect(printMessage).toHaveBeenCalledWith("Happy Columbus Zoo Panda") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Production Source | |
| var googlePandaStatus = function(disposition) { | |
| var aClosureScopedVar = 'Panda'; | |
| $.get('http://google.com',function(data) { | |
| printMessage(disposition+' '+data+' '+aClosureScopedVar); | |
| }); | |
| }; | |
| var printMessage = function() { /* imagine some terribly complex unrelated component that prints messages*/ } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment