嗨,我在运行我的测试时遇到了这个错误,我已经阅读了承诺并完成了,我仍然不确定在我的测试中把它放在哪里,或者最好在每个之前做一次,而不是为了避免重复?在哪里,什么是实现已完成的承诺的最佳方式?
错误:超过2000ms的超时时间。对于异步测试和钩子,请确保调用了"done()“;如果返回一个Promise,请确保它可以解析。
const chakram = require('chakram');
const expect = chakram.expect;
describe("Json assertions", function () {
it("Should return the matching test file and have a 200 response", function () {
let expected = require('../../test/fixtures/testfile.json');
let response = chakram.get("http://test");
expect(response).to.have.json(expected);
expect(response).to.have.status(200);
return chakram.wait();
});
});发布于 2017-08-11 22:47:53
我不熟悉chakram,但通常有一种模式可以测试您的承诺(使用done):
describe('Test Suite', function() {
it('should do something...', function(done) {
const testValue = 'testValue';
someAsyncFunction(testValue).then(function(result) {
result.should.have.property('foo');
result.should.have.property('bar');
done();
});
]);
});现在,就您所拥有的内容而言,docs for Chakram似乎展示了如何使用promises进行测试(在Promises标题下)。所以你改编的代码应该是这样的:
const chakram = require('chakram');
const expect = chakram.expect;
describe("Json assertions", function () {
it("should...", function () {
let expected = require('../../test/fixtures/testfile.json');
chakram.get("http://test").then(function(response) {
expect(response).to.have.json(expected);
expect(response).to.have.status(200);
});
});
});再说一次,我不知道那个库,但是如果你的测试运行人员仍然抱怨done,像这样添加done:
describe("Json assertions", function () {
it("should...", function (done) {
let expected = require('../../test/fixtures/testfile.json');
chakram.get("http://test").then(function(response) {
expect(response).to.have.json(expected);
expect(response).to.have.status(200);
done();
});
});
});编辑:done在describe块中,应该在it中。
https://stackoverflow.com/questions/45637674
复制相似问题