为了账号安全,请及时绑定邮箱和手机立即绑定

路由测试失败后

路由测试失败后

LEATH 2023-08-18 16:30:01
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条经验 获得超7个赞

您必须将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()

  });


查看完整回答
反对 回复 2023-08-18
  • 1 回答
  • 0 关注
  • 85 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信