我的快速POST路线是:
app.post("/addPost",function(req,res) {
let newComment = { post: req.body.createP,comment: req.body.createC };
myDB.push(newComment);
res.render("index.ejs",{ posts: myDB });
});
我的摩卡咖啡测试
describe("POST /",function() {
it("it ",function(done) {
supertest(myApp.app)
.post("/")
.expect(200)
.end(function(err,res) {
if (err) return done(err);
done();
});
});
});
手动,POST路由可以正常工作,但是mocha测试始终返回404而不是200。此外,GET路由的mocha测试也可以工作。有什么想法会导致这种情况吗?
另外,如何测试通过POST请求发送的html表单数据。预先感谢!