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
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
makeSpyMiddleware
✓ import makeSpyMiddleware from 'spy-middleware'
✗ const makeSpyMiddleware = require('spy-middleware')
Package is ESM-only; CommonJS require yields module.exports which is not the default export directly. Use named import or default import as shown.
default export
✓ import makeSpyMiddleware from 'spy-middleware'
✗ import { makeSpyMiddleware } from 'spy-middleware'
The package exports a default function; named import will not work.
spy middleware instance methods
✓ const spyMiddleware = makeSpyMiddleware(); spyMiddleware.getActions(); spyMiddleware.untilNext(); etc.
✗ makeSpyMiddleware().getActions()
Instance methods are available on the returned middleware object after creation, but you must apply it via applyMiddleware to a store for it to record actions.
Shows how to create spy middleware, apply to store, dispatch actions, get all actions, and wait for an action using untilNext.
import { createStore, applyMiddleware } from 'redux';
import makeSpyMiddleware from 'spy-middleware';
const spyMiddleware = makeSpyMiddleware();
const reducer = (state = [], action) => [...state, action.type];
const store = createStore(reducer, applyMiddleware(spyMiddleware));
store.dispatch({ type: 'FIRST' });
store.dispatch({ type: 'SECOND' });
console.log(spyMiddleware.getActions()); // [{ type: 'FIRST' }, { type: 'SECOND' }]
// Wait for a specific action
setTimeout(() => store.dispatch({ type: 'THIRD' }), 10);
spyMiddleware.untilNext('THIRD').then(action => console.log('Got:', action));
Errors
Common errors & fixes
TypeError: makeSpyMiddleware is not a function
Wrong import: used named import {} instead of default import, or used require which gives the module object.
fixUse default import: import makeSpyMiddleware from 'spy-middleware'
Actions not being recorded
Spy middleware not applied to store, or applied incorrectly (e.g., not last in chain).
fixEnsure spyMiddleware is passed to applyMiddleware and that the store is created with that enhancer.
Promise never resolves when using untilNext
The matching action was already dispatched before untilNext was called.
fixUse spyMiddleware.until() instead if you expect the action might have already fired.
spyMiddleware.untilNext is not a function
Using an old version or incorrect object; ensure you are calling untilNext on the result of makeSpyMiddleware().
fixConfirm you have version 1.0.0+ and that you created the middleware: const sm = makeSpyMiddleware(); then use sm.untilNext().
Audit
Dependencies
reduxrequiredPeer dependency required for middleware usage with createStore and applyMiddleware