Title: Jasmine + sinon fakeserver
Tags: jasmine;sinon
Question: So...I am writing tests in Jasmine for my GraphQL controller. The controller then depends on a fetcher function in another file that makes requests to WordPress for the data, which is then transformed for the GraphQL schema.
I am concerned that I may be operating on an incomplete understanding of how to implement the sinon fakeserver.
describe('graphql article by slug', function () {
var server;
beforeEach(() =&gt; {
server = sinon.fakeServer.create();
afterEach(() =&gt; {
server.restore();
it('should return the expected graphql result', function (done) {
var server = sinon.fakeServerWithClock.create();
server.respondWith(wpEndpoint, JSON.stringify(wpData()));
graphqlController
.loadJSON(request)
.then(function (result) {
console.log('result', result);
console.log('expectedData', expectedData());
expect(JSON.parse(result)).toEqual(JSON.parse(expectedData()));
done();
});
When I run the test above, I consistently get:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.


Here is another answer: You need to call server.respond(); to complete the requests, have a look at the documentation

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:02/04/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<jasmine><sinon>', 'Title': 'Jasmine + sinon fakeserver', 'ViewCount': 142, 'id': 35210835, 'user_AboutMe': None, 'user_AccountId': 24696.0, 'user_DisplayName': 'jerome', 'user_Reputation': 4637.0, 'user_Views': 320.0, 'user_id': 62983.0}}