describe("POST /post methods", () => {      it("should get /post ", (done) => {            const testing = {              name: "charanjit",              content: "im posting",              giph: ""            };            chai.request(server)              .post("/posts")              .send(testing)              .expect({                id: 4,                ...testing              }, done)服务器.jsserver.post("/posts", (req, res) => {      const incomingRequest = req.body;      if (isValidPost(incomingRequest)) {        const post = {          name: incomingRequest.name.toString(),          content: incomingRequest.content.toString(),          giph: incomingRequest.gif.toString(),          date: new Date(),          likes: 0,          dislikes: 0,          laughs: 0,          comments: [],          //id : database.length        };当我运行测试时,我得到TypeError: chai.request(...).post(...).send(...).expect is not a function。我尝试按照在线教程进行操作,但测试发布请求时不断收到错误,有人可以告诉我哪里错了吗?
                    
                    
                1 回答
 
                    
                    
                            largeQ
                            
                                
                            
                        
                        
                                                
                    TA贡献2039条经验 获得超8个赞
您必须将expect通话内容包含在内。
根据文档,调用应该是:
chai.request(app)
.put('/user/me')
.send({ password: '123', confirmPassword: '123' })
.end(function (err, res) {
expect(err).to.be.null;
expect(res).to.have.status(200);
});
所以尝试这样的事情:
chai.request(server)
.post("/posts")
.send(testing)
.end(function (err, res) {
expect(...)
done()
});
添加回答
举报
0/150
	提交
		取消
	