The res.setEncoding() must be respected when returning the mocked response.
const req = http.get('...')
req.on('response', (res) => {
res.setEncoding('base64')
res.on('data', collectChunks)
res.on('end', () => {
expect(collectedChunks).toEqual(base64string)
})
})
This must be added for each BufferEncoding:
type BufferEncoding = "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex";