Skip to content

Instantly share code, notes, and snippets.

@amirci
Created May 7, 2013 00:06
Show Gist options
  • Save amirci/5529301 to your computer and use it in GitHub Desktop.
Save amirci/5529301 to your computer and use it in GitHub Desktop.
Spec using mock to call response method
describe "ChildrenCheckinViewModel", ->
beforeEach ->
spyOn(jQuery, 'getJSON')
@actualChildren = ko.observableArray()
@subject = new Childcarepro.ChildrenCheckinViewModel @actualChildren
@response = [
{FIRSTNAME:'John',LASTNAME:'Locke',BIRTHDATE:12312312312},
{FIRSTNAME:'Matt',LASTNAME:'Zandstra',BIRTHDATE:12312312312}
]
@expectedChildren = [
new Childcarepro.Child(@response[0])
new Childcarepro.Child(@response[1])
]
describe "Ajax loading of children", ->
beforeEach -> @request = jQuery.getJSON.mostRecentCall
it "calls the children api", -> expect(@request.args[0]).toBe '/children.json'
it "loads all the children", ->
@request.args[2] {children: @response}, 200
expect(@subject.children().length).toBe 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment