Registry / testing / unexpected-express

unexpected-express

JSON →
library13.1.2jsnpmunverified

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.

npm install unexpected-express
INSTALL
IMPORT
SIG · UNEXPECTED-EXPRESS
U
unexpected-express
testingjavascriptv13.1.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import unexpected from 'unexpected'; import unexpectedExpress from 'unexpected-express'; unexpected.use(unexpectedExpress);
const unexpected = require('unexpected'); unexpected.use(require('unexpected-express'));
ESM only since v13; CommonJS require not supported
unexpectedExpress
import unexpectedExpress from 'unexpected-express';
import { unexpectedExpress } from 'unexpected-express';
Despite the name, the plugin is a default export, not a named export
expect
import expect from 'unexpected';
import { expect } from 'unexpected';
Unexpected's expect is a default export

Demonstrates testing an Express route that returns JSON based on request params

import unexpected from 'unexpected'; import unexpectedExpress from 'unexpected-express'; import express from 'express'; const expect = unexpected.clone().use(unexpectedExpress); const app = express(); app.get('/user/:id', (req, res) => { res.json({ id: req.params.id }); }); await expect(app, 'to yield exchange', { request: 'GET /user/42', response: { statusCode: 200, body: { id: '42' } } });
Debug
Known issues
breakingESM-only since version 13: CommonJS require() will not work
fix
Use import syntax or migrate to an older version (e.g., 12.x) if CJS required
affects: >=13.0.0
gotchaunexpected Express is a default export, not a named export
fix
Use `import unexpectedExpress from 'unexpected-express'`
affects: >=1.0.0
deprecatedThe plugin uses unexpected-messy internally; some low-level HTTP assertion methods may change
fix
Refer to unexpected-express documentation; avoid relying on unexpected-messy directly
affects: >=10.0.0
gotchaThe 'to yield exchange' assertion expects a full request string and response object; missing headers or body details may cause false failures
fix
Always specify at least statusCode and body if needed
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: unexpectedExpress is not a function
Using named import instead of default import
fix
Use `import unexpectedExpress from 'unexpected-express'`
Error: Cannot find module 'unexpected-express'
Package not installed or installed as dev dependency and missing in production
fix
Run `npm install --save-dev unexpected-express`
TypeError: expect(...).to is not a function
Forgetting to use the cloned expect instance with the plugin installed
fix
Use `const expect = unexpected.clone().use(unexpectedExpress);`
Upgrade
Version history
13.1.2latest on npm
Audit
Dependencies
unexpectedrequiredpeer dependency: required as the core assertion framework
expressrequiredpeer dependency: provides the middleware to test
unexpected-messyrequiredtransitive dependency for HTTP request/response assertions
Agent activity
7 hits · last 30 days
node
6
Resources
unexpected-express — npm install unexpected-express · libregistry