Javascript 如何使用模拟请求/响应对象测试express应用程序

Javascript 如何使用模拟请求/响应对象测试express应用程序,javascript,express,testing,Javascript,Express,Testing,下面的代码不起作用。我使用了节点模拟http。我只是想避免使用supertest,而是创建一个模拟的http.IncomingMessagehttp.ServerResponse对象 describe('Jest setup', () => { test('Get all accounts', async () => { const request = createRequest({ method: 'GET', url: '/api/accoun

下面的代码不起作用。我使用了
节点模拟http
。我只是想避免使用
supertest
,而是创建一个模拟的
http.IncomingMessage
http.ServerResponse对象

describe('Jest setup', () => {
  test('Get all accounts', async () => {
    const request = createRequest({
      method: 'GET',
      url: '/api/accounts',
    });
    const response = createResponse();

    await app(request, response);

    console.log(response._getData());
  });
});