intercept-response
v0.1.4
Published
Collects writes to Node.js http.ServerResponse
Downloads
5
Readme
intercept-response
Collects writes to Node.js http.ServerResponse and resolves to node-fetch Response
interceptResponse(res)
- res: http.ServerResponse - Node.js request object that you want to intercept (response does not get sent)
- returns Promise<Response> - resolves to node-fetch
Response
that corresponds to the written response
const { interceptResponse } = require('intercept-response');
const http = require('http');
http.createSever((req, res) => {
interceptResponse(res)
.then(fetchResponse => fetchResponse.text())
.then(text => assert(text === 'response body'));
res.writeHead(200);
res.end('response body');
});