title: How to unit test express-http-proxy
body: <p>I'm running a <strong>proxy service</strong> that adds a header to a request and forwards it to another API using <a href="https://www.npmjs.com/package/express-http-proxy" rel="nofollow noreferrer">express-http-proxy</a>:</p>
  
  <pre><code>app.use(
    proxy(proxyUrl, {
      proxyReqOptDecorator(proxyReqOpts, srcReq) {
        proxyReqOpts.headers.customHeader = 'custom header'
        return proxyReqOpts
      },
    })
  )
  </code></pre>
  
  <h2>Question:</h2>
  
  <p>How to unit test such a service?</p>
  
  <p>This is how I would test a normal express server:</p>
  
  <pre><code>describe('proxy service', function() {
    let server
    beforeAll(() =&gt; {
      server = app
    })
    afterAll(() =&gt; {
      server.close()
    })
  
    describe('successful execution', () =&gt; {
      test('responds to /', done =&gt; {
        request(server)
          .get('/')
          .expect(200, done)
      })
    })
  })
  </code></pre>
  
  <p>I want to validate what would be sent the external API without making the actual request.</p>