![](/img/trans.png)
[英]Unit test cases using Mocha and Chai. An Express Crud application. It contains basic curd operations(get, post, patch and delete )
[英]Nodejs api rest test with mocha and chai. Post pending
我正在学习做 api rest 测试,我遇到了使用 chai 和 mocha 的问题,我正在关注这个例子。
问题是 POST 方法总是挂起,根据挂起的东西并不意味着它失败了。 但是我想通过这个测试。
我的路线返回创建内容的json
,所以我不明白为什么测试没有通过,有人可以帮助我吗?
如果有帮助,请链接到存储库。
POST路由代码
router.post("/game", async (req, res) => {
const title = req.body.title
const year = req.body.year
const price = req.body.price
try {
const gameCreated = await Game.create({
title: title,
year: year,
price: price
})
res.json(gameCreated)
} catch (err) {
console.log(err)
res.sendStatus(500)
}
})
测试代码
describe("POST game test", () => {
it("must create a new game"), (done) => {
let game = {
title: "Game created by mocha",
year: 2020,
price: 178
}
chai.request('localhost:3033')
.post('/game')
.send(game)
.end((err, res) => {
res.should.have.status(200)
done()
})
}
})
你的测试有错字,你必须这样写:
it("must create a new game", (done) => {
但是你有
it("must create a new game"), (done) => {
注意)
不同
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.