Reputation: 79
I'm learning to do api rest tests and I came across a problem using chai and mocha, I was following this example.
The problem is that the POST method is always pending, according to something pending it does not mean that it failed. But I would like to pass this test.
My route is returning a json
of what was created, so I didn't understand why the test didn't pass, can someone help me with that?
Link to the repository if it helps.
POST route code
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)
}
})
Test code
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()
})
}
})
Upvotes: 0
Views: 292
Reputation: 15177
You have a typo in your test, you have to write like this:
it("must create a new game", (done) => {
But you have
it("must create a new game"), (done) => {
Note the )
different
Upvotes: 1