should-http extends the `should.js` assertion library with specific methods for validating Node.js HTTP `IncomingMessage` objects. Primarily used for testing HTTP requests and responses, it enables fluent assertions on status codes, headers (e.g., `Content-Length`), and content types (e.g., `application/json`, `text/html`). Currently at version 0.1.1, this package appears to be abandoned, with no active development or maintenance. Its approach of patching the global `should` instance, rather than exporting specific utilities, ties it closely to older `should.js` usage patterns and makes it less suitable for modern module development (ESM) where global side-effects are generally avoided. It focuses specifically on the standard Node.js `http` module's request and response objects, distinguishing it from broader HTTP client assertion libraries.
npm install should-httpVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to initialize `should-http` and use its core assertions (status, header, json, html) on a mock HTTP response object.
Consider migrating to a more actively maintained assertion library for HTTP testing, such as `chai-http` with `chai` or `supertest`.
Be aware that including `should-http` modifies global objects. If you encounter unexpected properties or assertion failures in unrelated tests, this global patching is a likely cause. Encapsulate test environments or use `should.js`'s non-prototypal usage if possible.
For ESM projects, consider assertion libraries that are natively designed for ESM or offer explicit ESM support. If you must use `should-http`, ensure your build process or Node.js runtime environment handles CJS interoperability correctly.
Ensure `require('should');` is called *before* `require('should-http');` to guarantee the `should` instance is available for patching.Verify that `should` is properly installed (`npm install should`) and required at the top of your test file, as per `should.js`'s standard usage. If using a test runner, ensure `should` is loaded correctly (e.g., via Mocha's `-r` flag).
Change `res.should.be.json` to `res.should.be.json()` to correctly invoke the assertion method. The same applies to `.html()`.