【发布时间】:2018-02-12 03:29:22
【问题描述】:
我正在创建一个具有登录后发布功能的应用程序。我在 mocha 中编写了以下测试代码。我收到此错误:
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
我认为我在使用 done() 时犯了一些错误。所有其他断言语句都已通过。如果您需要更多信息,请告诉我哪里出错了。
it("Login and post", function(done) {
superagent
.post(URL_ROOT + "/register")
.send({
email: "posttest@test.com",
password: "posttest"
})
.end(function(err, res) {
assert.ifError(err);
var token = res.body.token;
superagent
.post(URL_ROOT + "/post")
.send({
content: "testing post",
user: jwt.decode(token).id
})
.set("Authorization", "test_scheme " + token)
.end(function(err, res){
assert.ifError(err);
assert.equal(res.body.post.content, "testing post");
done();
});
});
});
【问题讨论】:
标签: javascript node.js testing mocha.js superagent