![](/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.