node-mocks-http icon indicating copy to clipboard operation
node-mocks-http copied to clipboard

The `sendFile` property is missing

Open ChrisMBarr opened this issue 9 months ago • 2 comments

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');

ChrisMBarr avatar Apr 26 '24 21:04 ChrisMBarr

Hi @ChrisMBarr thanks for reporting an issue.

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

eugef avatar Apr 29 '24 16:04 eugef

Stale issue message

github-actions[bot] avatar Jun 29 '24 00:06 github-actions[bot]

Stale issue message

github-actions[bot] avatar Sep 01 '24 01:09 github-actions[bot]