mercredi 18 novembre 2020

Test failing as TypeError: Cannot read property 'toString' of undefined

//testing POST methods
describe ("POST /post methods",() => {
  it("should get /post ",(done)=>{
     const testing = {
         name: "charanjit",
         content: "im posting",
         giph: ""

     };
     chai.request(server)
    .post("/posts")
    .send(testing)
    .end((err,response) =>{
          response.should.have.status(201);
         
           // response.body.should.have.property("id")
        should.exist(res.body);

   
        
response.body.should.have.property("name").eq("charanjit")
        response.body.should.have.property("giph").eq("")
        
response.body.should.have.property("content").eq("im posting")
        done()

    
    
    })

})

})

The file the error is referring to is the giph line:

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

Im new mocha and testing in general also javascript, I want to know whats causing this TypeError error? I tried searching online but I couldn't find a solution

Aucun commentaire:

Enregistrer un commentaire