{"repo":"eugef/node-mocks-http","free":true,"listed":false,"github":"https://github.com/eugef/node-mocks-http","clone":"git clone https://github.com/eugef/node-mocks-http.git","description":"Mock 'http' objects for testing Express,js, Next.js and Koa routing functions","language":"JavaScript","stars":773,"topics":["expressjs","nextjs","nodejs","testing"],"license":null,"category":"dev-tools","readme_excerpt":"--- [![NPM version][npm-badge]][npm-url] Mock 'http' objects for testing [Express][express-url], [Next.js][nextjs-url] and [Koa][koa-url] routing functions, but could be used for testing any [Node.js][node-url] web server applications that have code that requires mockups of the request and response objects. Installation This project is available as a [NPM package][npm-url]. or After installing the package include the following in your test files: Usage Suppose you have the following Express route: And you have created a function to handle that route's call: You can easily test the routeHandler function with some code like this using the testing framework of your choice: 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 expected type parameter in the mock request and response expects any type that extends the NodeJS http.IncomingRequest interface or Fetch API Request class. This means you can also mock requests coming from other frameworks too. An example for NextJS request will look like this: It is also possible to mock requests from the NextJS new AppRouter: API .createRequest() Where options is an object hash with any of the following values: option description default value --------------- -------------------------------- ------------- method r","default_branch":null,"files":null,"tree":[],"storefront":"/r/eugef","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/eugef/node-mocks-http/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}