unexpected-http is a plugin for the `unexpected` assertion library, specifically designed for testing HTTP servers and clients. It extends `unexpected`'s declarative syntax, allowing developers to write expressive assertions against HTTP requests and responses, mimicking the style of `unexpected-express`. As of version 9.0.0, it supports `unexpected` versions 10 through 13. The library enables fluent testing of server-side applications by asserting on status codes, headers, and body content of HTTP interactions. While its release cadence often aligns with its core `unexpected` dependency, it receives updates to maintain compatibility and introduce features relevant to HTTP testing. Its primary differentiator is its deep integration into the `unexpected` ecosystem, providing a consistent assertion experience across various testing scenarios, including frontend, backend, and API testing, by leveraging `unexpected`'s powerful diffing and introspection capabilities for failed assertions.
npm install unexpected-httpVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `unexpected-http` with an Express application and `supertest` to perform declarative HTTP assertions on status, headers, and JSON body content for various endpoints.
Review the changelogs for both `unexpected-http` and `unexpected` (especially for major versions) and update your test code and Node.js environment accordingly. Ensure your `unexpected` peer dependency matches the specified range for `unexpected-http`.
Upgrade or downgrade your `unexpected` package to a version that satisfies the `unexpected-http` peer dependency range (e.g., `^10.27.0 || ^11.12.1 || ^12.0.0 || ^13.0.0` for v9.0.0). Use `npm install unexpected@<version>` or `yarn add unexpected@<version>`.
Place `expect.use(unexpectedHttp);` at the top of your test suite or in a dedicated test setup file that runs before your tests. If using TypeScript, ensure `expect` is imported from 'unexpected' and the plugin is imported correctly.
Install `unexpected` in your project: `npm install unexpected` or `yarn add unexpected`.
Ensure `import { expect } from 'unexpected';` (or `const expect = require('unexpected').expect;`) is at the top of your test file, and `expect.use(unexpectedHttp);` is called to register the plugin.Examine the `peerDependencies` field in `unexpected-http`'s `package.json` (or the error message) and adjust your `unexpected` version to fit the range. For example, `npm install unexpected@^13.0.0` or `npm install --legacy-peer-deps` (use `legacy-peer-deps` with caution as a temporary workaround).