Skip to content

Instantly share code, notes, and snippets.

@hokuma
Created October 31, 2013 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hokuma/7250586 to your computer and use it in GitHub Desktop.
Save hokuma/7250586 to your computer and use it in GitHub Desktop.
jasmineでsinon.fakeServerを使うときに気をつけること ref: http://qiita.com/halhide/items/c27f1831b860145ca2a1
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();
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