I have a custom-proxy.ts
module that exports a function like this:
import proxy from 'express-http-proxy';
export const customProxy = proxy('a-url', {
filter: 'POST',
https: true
}
This is registered with an express route as follows:
server.all('/some/route', customProxy);
I would like to test that proxy
is called with the custom arguments using Jest.
I have tried to test it with the following approach:
import proxy from 'express-http-proxy';
import * as CustomProxy from 'custom-proxy';
import request from 'supertest';
describe('test', () => {
customProxySpy = jest.spyOn(CustomProxy, 'customProxy');
beforeEach(() => {
server = express;
server.all('/some/route', customProxy);
});
it('should pass', async () => {
await request(server).get('/some/route').send();
expect(customProxySpy).toHaveBeenCalledWith('a-url', {
filter: 'POST',
https: true
});
});
});
However the customProxySpy
is getting called with IncomingMessage
and some headers.
Does anyone know how I can verify the custom arguments get called in proxy()
?