node-mocks-http
node-mocks-http copied to clipboard
The `sendFile` property is missing
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');
Hi @ChrisMBarr thanks for reporting an issue.
This project heavily relies on contributors, so would be great if you can also submit a fix.
Stale issue message
Stale issue message