jerome
jerome

Reputation: 4987

Jasmine + sinon fakeserver

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(() => {
    server = sinon.fakeServer.create();
  });

  afterEach(() => {
    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.

Upvotes: 0

Views: 150

Answers (1)

grgmo
grgmo

Reputation: 1015

You need to call server.respond(); to complete the requests, have a look at the documentation

Upvotes: 0

Related Questions