{"id":18896,"library":"unexpected-express","title":"unexpected-express","description":"Plugin for the Unexpected assertion library that allows testing Express.js middleware by simulating HTTP requests and inspecting responses, status codes, headers, and body. Current stable version 13.1.2. Released as needed, follows semver. Differentiators: uses unexpected-messy for powerful HTTP assertion capabilities, integrates deeply with Unexpected's fluent API, and supports Express 4.x.","status":"active","version":"13.1.2","language":"javascript","source_language":"en","source_url":"git://github.com/unexpectedjs/unexpected-express","tags":["javascript","express","http","middleware","mock","test","unexpected"],"install":[{"cmd":"npm install unexpected-express","lang":"bash","label":"npm"},{"cmd":"yarn add unexpected-express","lang":"bash","label":"yarn"},{"cmd":"pnpm add unexpected-express","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency: required as the core assertion framework","package":"unexpected","optional":false},{"reason":"peer dependency: provides the middleware to test","package":"express","optional":false},{"reason":"transitive dependency for HTTP request/response assertions","package":"unexpected-messy","optional":false}],"imports":[{"note":"ESM only since v13; CommonJS require not supported","wrong":"const unexpected = require('unexpected'); unexpected.use(require('unexpected-express'));","symbol":"default","correct":"import unexpected from 'unexpected'; import unexpectedExpress from 'unexpected-express'; unexpected.use(unexpectedExpress);"},{"note":"Despite the name, the plugin is a default export, not a named export","wrong":"import { unexpectedExpress } from 'unexpected-express';","symbol":"unexpectedExpress","correct":"import unexpectedExpress from 'unexpected-express';"},{"note":"Unexpected's expect is a default export","wrong":"import { expect } from 'unexpected';","symbol":"expect","correct":"import expect from 'unexpected';"}],"quickstart":{"code":"import unexpected from 'unexpected';\nimport unexpectedExpress from 'unexpected-express';\nimport express from 'express';\n\nconst expect = unexpected.clone().use(unexpectedExpress);\n\nconst app = express();\napp.get('/user/:id', (req, res) => {\n  res.json({ id: req.params.id });\n});\n\nawait expect(app, 'to yield exchange', {\n  request: 'GET /user/42',\n  response: { statusCode: 200, body: { id: '42' } }\n});","lang":"typescript","description":"Demonstrates testing an Express route that returns JSON based on request params"},"warnings":[{"fix":"Use import syntax or migrate to an older version (e.g., 12.x) if CJS required","message":"ESM-only since version 13: CommonJS require() will not work","severity":"breaking","affected_versions":">=13.0.0"},{"fix":"Use `import unexpectedExpress from 'unexpected-express'`","message":"unexpected Express is a default export, not a named export","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Refer to unexpected-express documentation; avoid relying on unexpected-messy directly","message":"The plugin uses unexpected-messy internally; some low-level HTTP assertion methods may change","severity":"deprecated","affected_versions":">=10.0.0"},{"fix":"Always specify at least statusCode and body if needed","message":"The 'to yield exchange' assertion expects a full request string and response object; missing headers or body details may cause false failures","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use `import unexpectedExpress from 'unexpected-express'`","cause":"Using named import instead of default import","error":"TypeError: unexpectedExpress is not a function"},{"fix":"Run `npm install --save-dev unexpected-express`","cause":"Package not installed or installed as dev dependency and missing in production","error":"Error: Cannot find module 'unexpected-express'"},{"fix":"Use `const expect = unexpected.clone().use(unexpectedExpress);`","cause":"Forgetting to use the cloned expect instance with the plugin installed","error":"TypeError: expect(...).to is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}