# Pact JS

JavaScript consumer\-driven contract tests for HTTP and message\-based integrations\.

ID: Q194 · Revision: 178

Type: software · License: MIT[^pact-js-license] · Status: active

Website: https://docs.pact.io/implementation_guides/javascript/



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\.[^pact-js-readme][^pact-intro]

## 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\.[^pact-consumer][^pact-intro]

## 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\.[^pact-functional]

## 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\.[^pact-js-messages]

## 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\.[^pact-js-license][^pact-js-runtime][^pact-broker-intro]

## Substitution scope

Pact JS can substitute for [Specmatic](/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\.[^pact-intro][^pact-js-readme][^specmatic-model]

## Capabilities and substitutions

### Consumer\-driven contracts — supported

Actual consumer tests generate interactions for provider verification\.[^pact-intro][^pact-consumer]

Use case: Consumer/provider interface compatibility · Platforms: Node\.js 22\+ for inspected 17\.1\.4 · Region: Version, plan and platform requirements apply

### Message handler contracts — supported

Tests message contents while abstracting the transport intermediary\.[^pact-js-messages]

Use case: Consumer/provider interface compatibility · Platforms: Node\.js 22\+ for inspected 17\.1\.4 · Region: Version, plan and platform requirements apply

### Provider business side effects — unsupported

Contract verification does not establish functional side effects such as persistence\.[^pact-functional]

Use case: Consumer/provider interface compatibility · Platforms: Node\.js 22\+ for inspected 17\.1\.4 · Region: Version, plan and platform requirements apply

### [Substitute for Specmatic](/specmatic) — limited

Can replace interface\-compatibility testing with JavaScript consumer\-driven examples; schema\-driven coverage and artifacts differ\.[^pact-js-readme][^pact-intro][^specmatic-model]

Use case: Consumer/provider interface compatibility · Platforms: Node\.js 22\+ for inspected 17\.1\.4 · Region: Version, plan and platform requirements apply

## References

[^pact-js-license]: [Pact JS license](<https://github.com/pact-foundation/pact-js/blob/master/LICENSE>) — MIT license (vendor; retrieved 2026-10-07T11:14:41Z)

[^pact-js-readme]: [Pact JS repository](<https://github.com/pact-foundation/pact-js/blob/master/README.md>) — JavaScript contract testing and framework integration (vendor; retrieved 2026-10-07T11:14:26Z)

[^pact-intro]: [Pact introduction](<https://docs.pact.io/>) — Consumer\-driven contracts by example (vendor; retrieved 2026-10-07T11:14:10Z)

[^pact-consumer]: [Writing Pact consumer tests](<https://docs.pact.io/consumer>) — Exercise actual consumer logic rather than mock\-only calls (vendor; retrieved 2026-10-07T11:14:10Z)

[^pact-functional]: [Contract tests versus functional tests](<https://docs.pact.io/consumer/contract_tests_not_functional_tests>) — Message compatibility is not side\-effect verification (vendor; retrieved 2026-10-07T11:14:10Z)

[^pact-js-messages]: [Pact JS event\-driven systems](<https://docs.pact.io/implementation_guides/javascript/docs/messages>) — Message\-content abstraction and handler adapters (vendor; retrieved 2026-10-07T11:15:17Z)

[^pact-js-runtime]: [Pact JS package metadata](<https://github.com/pact-foundation/pact-js/blob/master/package.json>) — Version 17\.1\.4 engines\.node requires \>=22 (vendor; retrieved 2026-10-07T11:16:07Z)

[^pact-broker-intro]: [Pact Broker introduction](<https://docs.pact.io/pact_broker>) — Self\-hosted contract/result sharing versus managed PactFlow (vendor; retrieved 2026-10-07T11:14:10Z)

[^specmatic-model]: [Specmatic spec\-driven development](<https://docs.specmatic.io/contract_driven_development>) — Executable specifications and mock validation (vendor; retrieved 2026-10-07T11:14:19Z)

Source revision: https://substitutefor.net/entities/Q194?revision=178
