I use supertest to test web API, and I created a function to get the token,
module.exports.getToken = () => {
let query =
{
"email": config.dev.adminUsername,
"password": config.dev.adminPassword,
"applicationId": config.dev.applicationId
}
request(config.dev.loginUrl)
.post('/login')
.send(query)
.expect(200)
.then(res => {
console.log(res);
})
.catch(err => {
console.log(err);
});
}
but I got error looks like,
{ SyntaxError: Unexpected token e in JSON at position 0
at JSON.parse (<anonymous>)
at IncomingMessage.res.on (C:\WorkSpace\Postman\saasify-integration-tests\supertest_testScripts\node_modules\superagent\lib\node\parsers\json.js:11:35)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:139:11)
at process._tickCallback (internal/process/next_tick.js:181:9)
rawResponse: 'eyJraWQiOiJ4eGh5cXV3.................FRfeCpAm3sYxY7fV-WDK1w',
statusCode: 200,
response: undefined }
But same request and url in postman I can get the token string without error. what I did wrong?