Pact JS JavaScript consumer-driven contract tests for HTTP and message-based integrations.
Overview Pact JS is the JavaScript implementation of Pact's consumer-driven contract-testing approach. Consumer tests generate examples of expected interactions, which a provider verifies separately, helping teams detect incompatible request and response assumptions without exercising the whole distributed system together.[2] [3]
Contents Testing the real consumer A useful consumer test invokes the application's actual API client or message handler against Pact's test double. Calling the mock with a generic HTTP library while bypassing that application logic can generate a contract without testing how the consumer constructs requests or processes responses. Contracts describe the interactions consumers rely on rather than every possible behavior of the provider's complete API.[3] [4]
What verification establishes Pact focuses on agreement about messages and their structure. It does not establish that a provider persisted a record or performed another business side effect correctly; those are functional-test responsibilities. The distinction allows a provider to change internal rules without unnecessarily breaking consumer contracts, but it also means contract success is not a substitute for the provider's own business-logic tests.[5]
Message-based systems Pact JS also tests asynchronous and synchronous message interactions. Its message approach abstracts the transport and stands in for the intermediary while checking the data handled or produced by application functions. Small adapters may be needed to fit the expected handler interface. This validates message compatibility, not the live configuration or delivery guarantees of a particular queue or broker.[6]
Runtime, licensing and contract exchange The JavaScript library is MIT-licensed; inspected package metadata for version 17.1.4 requires Node.js 22 or newer. Contract files and provider-verification results can be shared through the separately deployed Pact Broker. Its documentation distinguishes self-hosting, which requires administration, from managed PactFlow. Using the library therefore does not itself provide a hosted contract registry or remove the need to coordinate provider verification.[1] [7] [8]
Substitution scope Pact JS can substitute for Specmatic for interface-compatibility checks when a JavaScript team wants consumers' executable examples to define the tested contract. Specmatic instead emphasizes reusable API specifications for tests and mocks. This is a choice of testing workflow, not compatible contract files or identical coverage: replacing schema-driven checks requires deciding which consumer assumptions and unconsumed API surfaces still need separate validation.[2] [3] [9]
Also included: 3 capabilities and 0 substitute relationships. Check substitutes in section 1 and capabilities in section 3.