Node.js Nodejs api rest测试与摩卡和柴。待决职位
我正在学习api rest测试,在使用chai和mocha时遇到了一个问题,我一直在关注 问题是POST方法总是挂起的,根据挂起的内容,这并不意味着它失败。但是我想通过这个测试。Node.js Nodejs api rest测试与摩卡和柴。待决职位,node.js,rest,mocha.js,integration-testing,chai,Node.js,Rest,Mocha.js,Integration Testing,Chai,我正在学习api rest测试,在使用chai和mocha时遇到了一个问题,我一直在关注 问题是POST方法总是挂起的,根据挂起的内容,这并不意味着它失败。但是我想通过这个测试。 我的路线是返回一个创建内容的json,所以我不明白为什么测试没有通过,有人能帮我吗 如果有帮助,请链接到 邮政路线代码 router.post("/game", async (req, res) => { const title = req.body.title const y
我的路线是返回一个创建内容的
json
,所以我不明白为什么测试没有通过,有人能帮我吗
如果有帮助,请链接到
邮政路线代码
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(“必须创建新游戏”,(完成)=>{
但是你有
it(“必须创建新游戏”),(完成)=>{
注意
)
不同的谢谢你,我的朋友,你帮助了我,现在它工作了!由于我在getById中遇到了不同的错误,我将打开另一个主题。谢谢你的帮助。