supertest
supertest copied to clipboard
TypeError: Cannot read properties of undefined (reading 'statusCode')
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')
tip: write the extension for syntax highlight when writing markdown in github
```js code ```