While the problem isn't actually solved, I have worked around this issue by using a slightly different syntax for Sinon.
Here is my test suite:
describe( "Transfer", function(){
var suite = this;
beforeEach( function(){
suite.server = sinon.fakeServer.create();
});
afterEach( function(){
suite.server.restore();
});
describe( "#loadSomeData", function(){
it( "should load the test data", function( done ){
var async = Transfer.loadSomeData( 123 );
suite.server.requests[0].respond(
200,
{ "Content-Type": "application/json" },
JSON.stringify({test: "success"})
);
async.done( function( data, s, x ){
data.test.should.equal( "success" );
done();
});
});
});
});
As you can see, instead of simply instructing the server to respond, I explicitly select the first request object (requests[0]
), then call the respond method on it.
I don't know if the previous syntax (server.respond()
) actually works, but explicitly selecting the request object from the list of requests the server has received and responding to it directly works fine.