eugef / node-mocks-http

Mock 'http' objects for testing Express,js, Next.js and Koa routing functions
Other
755 stars 134 forks source link

The `sendFile` property is missing #301

Closed ChrisMBarr closed 2 weeks ago

ChrisMBarr commented 5 months ago

As mentioned before in issues #88 and #245 (which were both closed without resolving!) the sendFile method is missing from this implementation. The TypeScript typedefs say it is there, but it is not at runtime.

To reproduce in a Jest test:

import * as httpMock from 'node-mocks-http';

const res = httpMock.createResponse();
jest.spyOn(res, 'sendFile');
//               ^^^^^^^^  Property `sendFile` does not exist in the provided object

My temporary workaround to allow me to mock this method is to do this:

import * as httpMock from 'node-mocks-http';

export function createMockResponse() {
  const res = httpMock.createResponse();
  res.sendFile = () => {};
  return res;
}
import { createMockResponse } from '../test-helpers';

const res = createMockResponse();
jest.spyOn(res, 'sendFile');
eugef commented 5 months ago

Hi @ChrisMBarr thanks for reporting an issue.

This project heavily relies on contributors, so would be great if you can also submit a fix.

github-actions[bot] commented 3 months ago

Stale issue message

github-actions[bot] commented 1 month ago

Stale issue message