jeudi 19 novembre 2020

post route test failing

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)

Server.js

server.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
        };

When I run the test I getTypeError: chai.request(...).post(...).send(...).expect is not a function.

I tried following tutorial online and I keep getting error for testing post request, can someone tell me where I am wrong?

Aucun commentaire:

Enregistrer un commentaire