Created
October 31, 2013 14:18
-
-
Save hokuma/7250586 to your computer and use it in GitHub Desktop.
jasmineでsinon.fakeServerを使うときに気をつけること ref: http://qiita.com/halhide/items/c27f1831b860145ca2a1
This file contains 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
var server = sinon.fakeServer.create(); | |
server.autoRespond = true; | |
server.respondWith( function( xhr, id ) { | |
xhr.respond( 200, null, "..." ); | |
} ); | |
spyOn( someObject, "somemethod" ); | |
hogeClient.request( ... ); | |
expect( someObject.somemethod ).toHaveBeenCalled(); |
This file contains 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
runs( function() { | |
var server = sinon.fakeServer.create(); | |
server.autoRespond = true; | |
server.respondWith( function( xhr, id ) { | |
xhr.respond( 200, { "content-type": "application/json" }, JSON.stringify( { entries: { ... } ) ); | |
} ); | |
spyOn( someObject, "somemethod" ); | |
hogeClient.request( ... ); | |
} ); | |
waitsFor( function() { | |
return someObject.somemethod.wasCalled; | |
}, "timeout", 3000 ); | |
runs( function() { | |
expect( someObject.somemethod ).toHaveBeenCalled(); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment