亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

路由測試失敗后

路由測試失敗后

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條經驗 獲得超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()

? });


查看完整回答
反對 回復 2023-08-18
  • 1 回答
  • 0 關注
  • 146 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號