{"library":"mock-req-res","title":"mock-req-res","description":"Library for creating mock Express request and response objects for unit testing controllers and middleware. Version 1.2.1 works with Sinon >10.0.0 and Node >=8.10.0. Provides mockRequest and mockResponse functions that return sinon stubs/spies for all standard Express req/res properties. Supports extensibility via options parameter. Lightweight and focused on isolated unit tests, unlike full integration tools like supertest. Includes TypeScript definitions via @types/mock-req-res. Release cadence is slow, with minor updates as needed.","language":"javascript","status":"active","last_verified":"Sat Apr 25","install":{"commands":["npm install mock-req-res"],"cli":null},"imports":["import { mockRequest } from 'mock-req-res'","import { mockResponse } from 'mock-req-res'","import { mockRequest, mockResponse } from 'mock-req-res'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const { mockRequest, mockResponse } = require('mock-req-res');\nconst sinon = require('sinon');\n\n// Sample controller that uses req.body and res.json\nconst createThing = (req, res) => {\n  const { name, description } = req.body;\n  if (!name || !description) {\n    return res.status(400).json({ error: 'Invalid properties' });\n  }\n  res.json({ id: 1, name, description });\n};\n\n// Test setup\nconst req = mockRequest({ body: { name: 'test', description: 'desc' } });\nconst res = mockResponse();\n\n// Invoke controller\ncreateThing(req, res);\n\n// Assertions\nconsole.log(res.json.calledOnce); // true\nconsole.log(res.json.firstCall.args[0]); // { id: 1, name: 'test', description: 'desc' }\nconsole.log(res.status.called); // false (no error)","lang":"javascript","description":"Shows basic usage: creating mock req and res, invoking a controller, and asserting on sinon stubs/spies.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}