node.js – Spy AWS SDK actual HTTP request with jest

I am trying to spy on the actual HTTP request made by the AWS SDK to verify that gzip is used in the data sent to the AWS. The compression is done using the Request onAsync(‘build’) listener:

// AWS.Request interface 
onAsync(event: "build", listener: (request: Request<D, E>) => void, prepend?: boolean): Request<D, E>;

// Compression functionality
.onAsync('build', (req) => {
  req.httpRequest.headers['Content-Encoding'] = 'gzip';
  gzip(req.httpRequest.body, (_err, result) => {
    req.httpRequest.body = result;
  });
})

This far I have only succeeded to spy on the AWS Service makeRequest with jest like this:

const requestSpy = jest.spyOn(AWS.Service.prototype, 'makeRequest');

Is there an easy way to spy on the actual HttpRequest sending to verify that the headers are correct and data is actually compressed?

Thanks!

Read more here: Source link