因此,我正在用Jasmine为我的GraphQL控制器编写测试。然后,控制器依赖于另一个文件中的抓取器函数,该函数向WordPress请求数据,然后将数据转换为GraphQL模式。
我担心我可能对如何实现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();
});
});
});当我运行上面的测试时,我总是得到:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
发布于 2016-09-17 22:59:58
您需要调用server.respond();来完成请求,请看一下documentation
https://stackoverflow.com/questions/35210835
复制相似问题