Skip to content
Latchkey

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.

Pact JS
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

  1. Await the Verifier and surface the rejection so CI fails clearly.
  2. Read the per-interaction diff in the logs above the error.
  3. Fix the provider or contract and re-run.
provider.verify.js
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.

provider.verify.js
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.

Frequently asked questions

What causes ""PactVerificationError""?
The provider response differs from the contract for at least one interaction, so the Verifier promise rejects.
How do I fix "PactVerificationError"?
Handle the rejection and read the diff

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card