intercept-response
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

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');
});

/intercept-response/

    Package Sidebar

    Install

    npm i intercept-response

    Weekly Downloads

    0

    Version

    0.1.4

    License

    MIT

    Unpacked Size

    32 kB

    Total Files

    12

    Last publish

    Collaborators

    • wmsmacdonald