Node.js library designed to facilitate unit and integration testing of Express.js middleware and route handlers by providing a mock HTTP response object. It emulates the standard Express `response` API, including methods like `json()`, `send()`, and `render()`, allowing developers to inspect the output and behavior of their Express-dependent code without launching a full HTTP server. The package, currently at version 0.3.0, appears to be unmaintained; its last update was in 2017 and the copyright dates to 2015. It is built upon `mock-res` for core HTTP response stream mocking and is intended to be used in conjunction with `mock-express-request` for a complete request/response mock pair. A key differentiator is its direct mirroring of the Express `res` object's internal state, allowing retrieval of rendered data via methods like `_getJSON()` and `_getString()`, which simplifies assertion writing in tests. Due to its age, compatibility with modern Express.js versions (v5+) and native ESM environments is not guaranteed.
npm install mock-express-responseVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic instantiation and usage of `MockExpressResponse` with common Express methods (`json`, `render`, `send`), and how to retrieve the mocked output for assertions.
For new projects or those using modern Express/Node.js, consider custom mocks or more actively maintained alternatives. If used, pin the `express` peer dependency to a compatible version (v3 or v4) in your `package.json`.
Ensure your project or test files are configured for CommonJS, or use dynamic `import()` for ESM projects: `const MockExpressResponse = await import('mock-express-response');` (though this might still encounter issues with the CJS module structure).Ensure you are using `const MockExpressResponse = require('mock-express-response');` in a CommonJS file.Verify that your `express` peer dependency version is compatible with this library (Express v3 or v4). If using a newer Express version, this package is likely incompatible; consider manually mocking the `res` object or using a different testing approach.