supertest icon indicating copy to clipboard operation
supertest copied to clipboard

TypeError: Cannot read properties of undefined (reading 'statusCode')

Open varsha766 opened this issue 4 years ago • 1 comments

I am using chai and mocha using request package for testing APIs

var expect = require('chai').expect;
var request = require('request');

const HypersignAuthToken = 'auth_token_value';
const projectData =
{
  "projectName": "demo-test-26",
  "logoUrl": "http://localhost:3000",
  "fromDate": "2021-12-15",
  "toDate": "2021-12-18",
  "actions": [],
  "refereePoint": 5,
  "referralPoint": 10,
  "projectStatus": 1
}
 
it('should add (POST) new event', function (done) {
  const tempProjectData = { ...projectData };
  request
    .post({
      url: 'http://localhost:6006/api/v1/project',
      body: tempProjectData,
      'auth': {
        'bearer': HypersignAuthToken
      }
    },
      function (error, response, body) {
      
        expect(response.statusCode).to.equal(200)
        expect(response.body).to.be.a('object')
        console.log('statusCode:',response && response.statusCode);
        done();
      })

    })

I am getting error:-

TypeError: Cannot read properties of undefined (reading 'statusCode')

varsha766 avatar Dec 19 '21 23:12 varsha766

tip: write the extension for syntax highlight when writing markdown in github

```js code ```

jimmywarting avatar Jan 10 '22 21:01 jimmywarting