eugef / node-mocks-http

Mock 'http' objects for testing Express routing functions
Other
747 stars 131 forks source link

Make it easier to create mocks for the node http library #256

Closed B3none closed 1 year ago

B3none commented 2 years ago

This is to prevent the need for me to set the destroy function handler myself when creating a request for the http library. Since the destroy function returns void we can just mock it as an empty function and don't need to action anything.

I'm not actually using express but this library is working for me with the core http library. This change saves me 1 line of additional code and makes it easier for other people using the library that aren't using express.

Before:

const mockRequest = httpMocks.createRequest();

mockRequest.destroy = jest.fn();

const mockResponse = httpMocks.createResponse();

handleRequest(mockRequest, mockResponse);

After:

const mockRequest = httpMocks.createRequest();

const mockResponse = httpMocks.createResponse();

handleRequest(mockRequest, mockResponse);
github-actions[bot] commented 1 year ago

Stale pull request message