{"id":16215,"library":"should-http","title":"should-http: HTTP Assertions for should.js","description":"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.","status":"abandoned","version":"0.1.1","language":"javascript","source_language":"en","source_url":"git://github.com/shouldjs/http","tags":["javascript","should","should.js","http"],"install":[{"cmd":"npm install should-http","lang":"bash","label":"npm"},{"cmd":"yarn add should-http","lang":"bash","label":"yarn"},{"cmd":"pnpm add should-http","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency, should-http patches `should.js` with additional HTTP assertions. Requires should.js version 4.x or higher.","package":"should","optional":false}],"imports":[{"note":"This package is a CommonJS module designed to be `require`d for its side effects, patching the global `should` instance. It does not export specific symbols for named or default imports. While technically `import 'should-http';` might work in ESM, the package is likely not tested or intended for modern ESM environments and could have compatibility issues with newer Node.js versions.","wrong":"import shouldHttp from 'should-http';","symbol":"* (side-effect import)","correct":"require('should-http');"}],"quickstart":{"code":"const should = require('should');\nrequire('should-http');\n\n// Simulate an HTTP response object\nconst mockResponse = {\n  statusCode: 200,\n  headers: {\n    'content-type': 'application/json; charset=utf-8',\n    'content-length': '123'\n  },\n  body: '{ \"key\": \"value\" }'\n};\n\n// Assertions using should-http\ntry {\n  mockResponse.should.have.status(200);\n  console.log('✔ Status code is 200');\n\n  mockResponse.should.have.header('content-length');\n  console.log('✔ Has content-length header');\n\n  mockResponse.should.have.header('Content-Length', '123');\n  console.log('✔ Content-Length header matches value');\n\n  mockResponse.should.be.json();\n  console.log('✔ Content-Type is application/json');\n\n  // Example of a failing assertion (uncomment to see it fail)\n  // mockResponse.should.have.status(404);\n\n} catch (e) {\n  console.error('Assertion failed:', e.message);\n}\n\n// Example for .html (if content-type were different)\nconst htmlResponse = {\n    statusCode: 200,\n    headers: {\n        'content-type': 'text/html; charset=utf-8'\n    }\n};\n\ntry {\n    htmlResponse.should.be.html();\n    console.log('✔ Content-Type is text/html');\n} catch (e) {\n    console.error('HTML assertion failed:', e.message);\n}","lang":"javascript","description":"Demonstrates how to initialize `should-http` and use its core assertions (status, header, json, html) on a mock HTTP response object."},"warnings":[{"fix":"Consider migrating to a more actively maintained assertion library for HTTP testing, such as `chai-http` with `chai` or `supertest`.","message":"This package is largely unmaintained and may not be compatible with newer versions of Node.js or `should.js` beyond the specified peer dependency (>= 4.x). Using older, unmaintained packages can introduce security vulnerabilities or unexpected behavior in modern environments.","severity":"breaking","affected_versions":"<=0.1.1"},{"fix":"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.","message":"should-http works by patching the global `should` instance (and by extension, potentially `Object.prototype` depending on `should.js` configuration). This can lead to global namespace pollution and conflicts with other libraries or unexpected side effects, which is a deprecated pattern in modern JavaScript development.","severity":"gotcha","affected_versions":"*"},{"fix":"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.","message":"This package is designed for CommonJS (`require`). While Node.js has robust interoperability, using a CJS module that relies on global side-effects within an ESM project might introduce subtle issues or require specific configuration (e.g., `--experimental-json-modules` or using bundlers).","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure `require('should');` is called *before* `require('should-http');` to guarantee the `should` instance is available for patching.","cause":"The `should-http` module was required before `should.js` was initialized, or `should.js` itself was not required/available in the environment.","error":"Error: should.js: assertion for 'status' was not added"},{"fix":"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).","cause":"The `should` library was not correctly loaded or applied, meaning `Object.prototype.should` (or `should(obj)`) is not available, and thus `res.should` fails.","error":"TypeError: Cannot read properties of undefined (reading 'should')"},{"fix":"Change `res.should.be.json` to `res.should.be.json()` to correctly invoke the assertion method. The same applies to `.html()`.","cause":"The assertion `json` is a method and requires parentheses `()` to be called, even though it takes no arguments.","error":"TypeError: 'res.should.be.json' is not a function"}],"ecosystem":"npm"}