Skip to content

Commit

Permalink
Adjusting Readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTail committed Oct 3, 2024
1 parent c9a4717 commit 4bd3479
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,20 @@ exports['routeHandler - Simple testing'] = function (test) {

### TypeScript typings

The typings for TypeScript are bundled with this project. In particular, the `.createRequest()`, `.createResponse()` and `.createMocks()` methods are typed and are generic. Unless specified explicitly, they will be return an Express-based request/response object:
The typings for TypeScript are bundled with this project. In particular, the `.createRequest()`, `.createResponse()` and `.createMocks()` methods are typed and are generic. You should explicitly specify the type of request/response object of your framework, otherwise the basic NodeJS `IncomingMessage` and `OutgoingMessage` are used:

```ts
import type { Request, Response } from 'express';

it('should handle expressjs requests', () => {
const mockExpressRequest = httpMocks.createRequest({
const mockExpressRequest = httpMocks.createRequest<Request>({
method: 'GET',
url: '/user/42',
params: {
id: 42
}
});
const mockExpressResponse = httpMocks.createResponse();
const mockExpressResponse = httpMocks.createResponse<Response>();

routeHandler(request, response);

Expand Down

0 comments on commit 4bd3479

Please sign in to comment.