我对Node JS非常陌生。我已经编写了一个swagger API,现在我正在使用mocha库为其编写测试用例。以下是我的test.js文件,但出现错误。
var assert = require("assert");
var should = require('chai').should();
var testAssistants = require("swagger-test");
describe('Test API', function () {
var invokeAPI;
before(function (done) {
testAssistants.parse('../api/swagger.yaml',
function (authInvoker, error) {
if (error) {
console.log("Cannot proceed: Swagger file is invalid");
error.every(function (error) {
console.log(error);
});
process.exit();
} else {
invokeAPI = authInvoker;
}
done();
});
});
describe('http://localhost:8080/v1/id/123/test', function () {
it('should give results', function (done) {
this.timeout(10000);
var result = invokeAPI("GET", "/v1/id/123/test", {});
let resJson = result._getJSON();
testAssistants.assertSwaggerResult(result, 200);
result.response.body.length.should.be.greaterThan(0);
should.equal(resJson.length, 2);
done();
});
});
})
我正在使用node_modules/.bin/mocha
运行测试类,并出现以下错误:
"before all" hook in "Test API":
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (D:\test-node-api\test\test.js)
我想念什么?