Pact "Actual interactions do not match expected" in CI
The Pact mock server compared the requests your consumer code actually made against the interactions the test declared, and they differ. It fails the consumer test before any pact file is written.
What this error means
A consumer test fails with "Actual interactions do not match expected interactions" and lists missing, unexpected, or altered requests captured by the mock server.
Pact verification failed - expected interactions did not match actual.
Missing requests:
GET /orders/42
Unexpected requests:
GET /orders/42?expand=itemsCommon causes
The client sent a different request than declared
The consumer added a query param, header, or path segment the interaction did not declare, so the mock server reports an unexpected request.
A declared interaction was never exercised
The test set up an interaction the code path did not call, so the mock server reports it as a missing request.
How to fix it
Match the interaction to the real request
- Compare the declared interaction with the actual request in the failure output.
- Update the interaction (or the client) so the method, path, query, and headers agree.
- Ensure every declared interaction is actually triggered by the test.
await provider.addInteraction({
state: 'order 42 exists',
uponReceiving: 'a request for order 42',
withRequest: { method: 'GET', path: '/orders/42', query: { expand: 'items' } },
willRespondWith: { status: 200, body: like({ id: 42 }) },
});Use matchers for dynamic query and headers
Where a value varies, match by type or regex so an equivalent request is accepted.
query: { expand: term({ matcher: 'items|all', generate: 'items' }) }How to prevent it
- Keep declared interactions in lockstep with the client code under test.
- Exercise every declared interaction so none is reported missing.
- Use matchers for query params and headers that vary at runtime.