Pact JS "@pact-foundation ... PactVerificationError" in CI
The @pact-foundation/pact Verifier rejects with PactVerificationError when one or more interactions fail. The rejection message includes the per-interaction diff so you can see which expectation the provider did not meet.
What this error means
A Node provider verification script rejects with "PactVerificationError: Pact verification failed" and a summary of failed interactions.
PactVerificationError: Pact verification failed - see logs above
at Verifier.verifyProvider (@pact-foundation/pact/src/dsl/verifier/verifier.js)
1 interaction failed: a request for order 42 (body mismatch)Common causes
One or more interactions did not match
The provider response differs from the contract for at least one interaction, so the Verifier promise rejects.
State handlers or provider base URL misconfigured
A missing stateHandlers entry or a wrong providerBaseUrl causes interactions to fail before the body is even compared.
How to fix it
Handle the rejection and read the diff
- Await the Verifier and surface the rejection so CI fails clearly.
- Read the per-interaction diff in the logs above the error.
- Fix the provider or contract and re-run.
try {
await new Verifier(opts).verifyProvider();
} catch (e) {
console.error(e);
process.exit(1);
}Provide state handlers and the correct base URL
Register a handler for every provider state and point providerBaseUrl at the running app.
const opts = {
provider: 'orders-provider',
providerBaseUrl: 'http://localhost:8080',
stateHandlers: { 'order 42 exists': async () => seed(42) },
};How to prevent it
- Always await and handle the Verifier promise so failures fail CI.
- Register state handlers for every provider state.
- Health-check the provider before verifying.