- Nock version: ^10.0.4
The request below always returns response
as String. I need JSON format instead. Right now I cannot get res.data
(return undefined), but I can see res
as String.
How do I get JSON format of the response?
Here is my request:
nock('https://api.smartsheet.com/2.0/sheets/')
.defaultReplyHeaders({
"accept-encoding":"gzip, deflate",
"accept": "application/json",
"content-type": "application/json"
})
.get('/')
.reply(200, {"data" : "test"});
- I tried use JSON.parse({"data": "test"), it still returns String as a response.
- I also tried
const buffer = Buffer.from(JSON.stringify({data: 'test'}));
const compressed = zlib.gzipSync(buffer);
nock('https://api.smartsheet.com/2.0/sheets/')
.defaultReplyHeaders({
"accept-encoding":"gzip, deflate",
"accept": "application/json",
"content-type": "application/json"
})
.get('/', compressed)
.reply(200, () => compressed);
But I don't know how to send binary buffer in nock.
How do I send binary buffer in Get request?
Requesting code:
this.smartsheet = SmartsheetClient({
accessToken: this.config.get('smartsheet.oauth_token'),
});
const [getError, sheets] = await this.to(this.smartsheet.sheets.listSheets());
if (getError) {
throw new this.Doh('Fail to get sheets', getError);
}
return sheets.data;