https://pact.io logo
Join Slack
Powered by
# pact-js
  • m

    Martin Mineo

    03/07/2025, 1:16 PM
    @Martin Mineo has left the channel
  • b

    Bertrand Ernst

    03/13/2025, 1:25 PM
    Hello folks ! I was wondering if it is possible to manage the pact-mock server outside of
    pact-js
    ? To be more precise, I would like to manage the mock server myself using the
    pact-cli
    Docker image instead of having
    pact-js
    launch a mock-server for me. I looked at the options to setup the provider with the
    host
    and
    port
    of a running mock-server but couldn't find anything. Is this at all possible? Thanks in advance !
    y
    • 2
    • 3
  • g

    Gabriel Vasconcelos

    03/17/2025, 2:04 PM
    Hello team, how can I validate an enum of integers in pact JS? Is it possible? or only for strings?
    m
    r
    • 3
    • 13
  • l

    Lachlan Newman

    03/18/2025, 5:05 AM
    hey guys is there a way to use matchers to be one of a union type ? for example i want a key to be of type null or any string ?
    m
    s
    • 3
    • 4
  • b

    Bertrand Ernst

    03/28/2025, 11:05 AM
    Hey guys ! I use
    pact-js
    along with
    jest
    . Above every test suite that is executed, I have the following error message:
    Copy code
    Failed to initialise global tracing subscriber - a global default trace dispatcher has already been set
    As I understand, this comes from the reference implementation where there are several instance of such error message being sent: https://github.com/search?q=repo%3Apact-foundation%2Fpact-reference%20set_global_default&type=code I initialize my provider using
    new PactV3(...)
    in a
    beforeEach
    block within a
    setupFilesAfterEnv
    file (is this best practice?). https://jestjs.io/docs/configuration#setupfilesafterenv-array What is the best way to get rid of this error? Note that it's not blocking, my tests run just as well but it's annoying. 🙂
    m
    • 2
    • 2
  • a

    Abubakar Mehmood

    03/31/2025, 10:24 AM
    Hello, folks! Have successfully published a consumer pact to Pactflow but having trouble verifying it from the provider. The provider is a NodeJS lambda function in which I start a server and essentially following the provider and its test from the e2e example. Facing two problems: 1. pactjs tries to hit the
    /_pactSetup
    endpoint but I haven't set it up
    (neither does the above-mentioned example). Logs:
    Copy code
    2025-03-31T07:33:34.581653Z DEBUG ThreadId(02) verify_interaction{interaction="a request to create a quote"}: hyper_util::client::legacy::connect::http: connecting to 127.0.0.1:51891
    2025-03-31T07:33:34.581929Z DEBUG ThreadId(02) verify_interaction{interaction="a request to create a quote"}: hyper_util::client::legacy::connect::http: connected to 127.0.0.1:51891
    [08:33:34.604] DEBUG (38248): pact@15.0.1: hooks state counter is 1 after receiving "setup" action
    [08:33:34.605] DEBUG (38248): pact@15.0.1: incoming request: {"body":{"action":"setup","params":{},"state":"quote can be created"},"headers":{"content-type":"application/json","accept":"*/*","accept-encoding":"gzip, deflate","host":"127.0.0.1:51891","content-length":"61"},"method":"POST","path":"/_pactSetup"}
    
    (followed by timeout)
    
    2025-03-31T07:34:04.691883Z DEBUG ThreadId(02) verify_interaction{interaction="a request to create a quote"}: pact_verifier::provider_client: State change request failed with error error sending request for url (<http://127.0.0.1:51891/_pactSetup>)
    While the docs here seem to mention that we need to set up an (or two, according to this old answer) HTTP endpoints for the states, I couldn't find any details of what the endpoints should look like, and how are the e2e tests working without setting up those endpoints. 2. pactjs seems to start its own mock server and call the endpoint to verify on that base URL instead of using the
    providerBaseUrl
    I've specified
    . Excerpt of code:
    Copy code
    const server = express();
    server.use(cors());
    const app = server.listen(53404, () => {
    console.log(`Server listening on <http://localhost:53404>`);
    });
    server.post('/v3/forex/quote', (req, res) => {
    res.append('Content-Type', 'application/json').status(200).send({
    dummy: 123456789, // This is supposed to be replaced in the request filters
    });
    });
    
    const opts = {
                provider: 'MyProvider',
                logLevel: "debug",
                providerBaseUrl: `<http://localhost:53404>`,
                stateHandlers: {
                    'quote can be created': async () => {
                        await redisClient.set("some data");
                        //console.log('handler finished');
                        return Promise.resolve();
                    },
                },
               
                // Override request handling to call the Lambda function directly
                requestFilter: async (req, res, next) => {
                 // omitted for brevity
                 }
            };
            const verifier = new Verifier(opts);
    Logs show a different port (53741), instead of 53404. It changes every time, though:
    Copy code
    2025-03-31T08:39:11.753646Z INFO ThreadId(02) verify_interaction{interaction="a request to create a quote"}: pact_verifier::provider_client: Sending request to provider at <http://127.0.0.1:53741/>
    2025-03-31T08:39:11.753655Z DEBUG ThreadId(02) verify_interaction{interaction="a request to create a quote"}: pact_verifier::provider_client: Provider details = ProviderInfo { name: "ForexV3-Funding", protocol: "http", host: "127.0.0.1", port: Some(53741), path: "/", transports: [ProviderTransport { transport: "http", port: Some(53741), path: Some("/"), scheme: Some("http") }] }
    2025-03-31T08:39:11.753676Z INFO ThreadId(02) verify_interaction{interaction="a request to create a quote"}: pact_verifier::provider_client: Sending request HTTP Request ( method: POST, path: /v3/forex/quote, query: None, headers: Some({"Content-Type": ["application/json"]}), body: Present(115 bytes, application/json) )
    2025-03-31T08:39:11.753689Z DEBUG ThreadId(02) verify_interaction{interaction="a request to create a quote"}: pact_verifier::provider_client: body:
    {"buy_amount":"18.358","buy_currency":"GBP","customer":{"id":"C-98YE32ZY"},"sell_currency":"USD","type":"customer"}
    2025-03-31T08:39:11.753743Z DEBUG ThreadId(02) verify_interaction{interaction="a request to create a quote"}: hyper_util::client::legacy::pool: reuse idle connection for ("http", 127.0.0.1:53741)
    [09:39:11.756] DEBUG (40620): pact@15.0.1: incoming request: {"body":{"buy_amount":"18.358","buy_currency":"GBP","customer":{"id":"C-98YE32ZY"},"sell_currency":"USD","type":"customer"},"headers":{"content-type":"application/json","accept":"*/*","accept-encoding":"gzip, deflate","host":"127.0.0.1:53741","content-length":"115"},"method":"POST","path":"/v3/forex/quote"}
    m
    • 2
    • 2
  • a

    Ayoub BOULAHTAR

    04/04/2025, 11:05 AM
    Hello community, I'm trying to write JS consumer tests with pact and vitest testing framework, I'm using PactV4, MatchersV3 from @pact-foundation/pact I can't find how to test a list of integers in the query builder, cf the code below, can anyone provide some insights please ?
    Copy code
    provider
    .addInteraction()
    .given('one or more requested row exist')
    .withRequest('GET', '/base/url', (builder) => {
      builder.query({
        ids: MatchersV3.eachLike(1),
      });
      builder.headers({
        'Content-Type': 'application/json',
      });
    })
    m
    • 2
    • 5
  • r

    Ruud Welling

    04/25/2025, 3:05 PM
    Hello, I am try to create a consumer test of a synchrounous message pact in pact-js. However I noticed several things: • The documentation about this is empty: https://docs.pact.io/implementation_guides/javascript/docs/messages#contract-testing-process-synchronous • I could not find any tests for this feature in the sdk (while looking for examples) The DSL seems to support creation of these tests, however when I run the test the contract file does not have a request and response. Is this feature not supported?
    m
    • 2
    • 3
  • n

    Neil McLaughlin

    05/02/2025, 9:03 AM
    Hi, I have a pact consumer test written in typescript. We are on “@pact-foundation/pact”: “^15.0.1". The test is currently working, but I would like to parameterise the url to make the contract somewhat less brittle. I’ve done this successfully in the past with the
    fromProviderState
    using the
    V3Interaction
    , but I can’t seem to get it working with the
    V4Interaction
    model. The
    fromProviderState
    call initially seems like its working in that the test passes, but the mock server seems to match any path, not just the specified path. Also, I’ve noticed that this method seems to have been dropped from the documentation in both the Java and JS versions of the pact documentation. The initial version (static path) is working, but it bakes a specific id into the contract.
    Copy code
    v4InteractionWithResponse = mockServer
          .addInteraction()
          .uponReceiving("a request for an advert")
          .given("basic car advert")
          .withRequest(
            "GET",
            "/product-page/v1/advert/201602281465747",
            (builder) => {
              builder.query({ channel: "cars" });
            },
          )
    So the next step was to parameterize the path using
    fromProviderState
    .
    Copy code
    v4InteractionWithResponse = mockServer
          .addInteraction()
          .uponReceiving("a request for an advert")
          .given("basic car advert")
          .withRequest(
            "GET",
            fromProviderState(
              "/product-page/v1/advert/${advertId}",
              "/product-page/v1/advert/201602281465747",
            ),
            (builder) => {
              builder.query({ channel: "cars" });
            },
          )
  • y

    Yassen Damyanov

    05/10/2025, 4:50 PM
    Hey Pact community đź‘‹ Quick question: is pact-js V3 still affected by this issue of representing
    Accept
    header values as an array as opposed to a comma delimited string? Details in 💬 ➡️
    m
    • 2
    • 4
  • j

    Jesse Vander Does

    05/19/2025, 2:35 PM
    Hi team, I have an API that is sending multipart/form-data containing both a binary and JSON data. I'm particularly interested in verifying the JSON data. I'm using PactV4 and have code like this. Two main questions: • When I add this sort of header declaration, I don't see anything related to the header show up in the pact file, why is that? • Is there a way that I can capture the contract that the server should handle the portion of the form containing JSON? I have seen some scattered references to multipart form data, but it seems like it may be for V3. I also couldn't find good examples for defining the structure of data within the form. Thanks in advance for any help.
    Copy code
    provider     
          .addInteraction()
          .given('a valid record can be saved')
          .uponReceiving('a request to save a record')
          .withRequest('POST', `/api/resource/${id}`, (builder) => {
            builder.headers(
                'multipart/form-data; boundary=.*',
            );
           })
    m
    • 2
    • 7
  • v

    Victor COATALEM

    06/19/2025, 10:31 AM
    Hello đź‘‹ I am trying to write a consumer test on pact-js V3. The request I want to test is a multipart form request , which contains a file as well as JSON metadata fields (
    source, reason, ...
    ). Basically I don't care about the file in itself, but I want to write matchers on the metadata fields. However I can't seem to make that work. Matching the
    reason
    field against anything yields the error:
    Failed to parse the expected body as a MIME multipart body: 'incomplete multipart stream'
    . I posted my example on this issue . Any input would be greatly appreciated 🙏
    m
    • 2
    • 3
  • t

    Teresa Marcelino

    06/23/2025, 3:32 PM
    Hey team 👋, I’m hitting a Pact test failure with a
    DELETE
    request. The mock expects a JSON request body like this:
    Copy code
    {
      "objectsIds": [
        1,
        2,
        3
      ]
    }
    But the test fails sayingfail:
    Expected body Present(45 bytes, application/json) but was empty
    My request call looks like this:
    Copy code
    makeRequestAcceptingJsonResponse("DELETE", mockServer.url, path, {
      objectsIds: [1, 2, 3],
    } /*payload*/);
    And my request function:
    Copy code
    return axios.request({
      baseURL,
      data: payload,
      headers: {
        Accept: "application/json",
        "Content-Type": "application/json",
      },
      method,
      url: path,
      validateStatus: () => true,
    });
    I suspect Axios might be dropping the body on DELETE requests. If I change to a POST, request body is being sent correctly. Has anyone seen this or knows how to fix it? Thanks! 🙏
    m
    y
    • 3
    • 4
  • z

    Zachary Lysobey

    06/24/2025, 9:40 PM
    I'm trying to figure out how to improve this section of the
    pact-js
    docs on Provider verification: > https://github.com/pact-foundation/pact-js/blob/master/docs/provider.md?plain=1#L122-L125
    Copy code
    const opts = {
      ...
      stateHandlers: {
        [null]: () => {
          // This is the "default" state handler, when no state is given
        }
        "Has no animals": () => {
          // ...
    There are a couple issues with this. 1) just above, it says "Here is an example from our e2e suite:". But the
    [null]
    case is not part of that example 2) its missing a comma after the
    [null]
    case, so the syntax is broken. 3) This works in JavaScript, but does not in TypeScript. TS is stricter with computed properties:
    > A computed property name must be of type 'string', 'number', 'symbol', or 'any'
    I think
    [null]
    would be coerced into
    "null"
    at runtime with JS, so maybe that works? I'm happy to make a PR fixing this. I'd of course add the missing
    ,
    , and I guess update
    [null]
    to be just
    "null"
    (?). But I'm not sure what to do about
    1)
    with the inaccurate note about the example code. Any advice?
    m
    • 2
    • 9
  • c

    Cody Jenkins

    07/14/2025, 7:55 AM
    I'm really confused by this. Based on my provider verification output, the provider verification results should be published to the broker, but they seem not to be? đź§µ
    đź‘‹ 1
    m
    • 2
    • 29
  • z

    Zachary Lysobey

    07/14/2025, 5:15 PM
    Does anyone have any good example(s) of multiple interactions in a single consumer test? Like, the consumer function I want to test through calls a sequence of provider endpoints. I'm struggling to put together a good pseudo-code example that makes sense...
  • z

    Zachary Lysobey

    07/14/2025, 7:59 PM
    I ended up doing some refactoring on this this up arrow to avoid that pattern all-together.
    m
    • 2
    • 1
  • z

    Zachary Lysobey

    07/14/2025, 8:01 PM
    An aside, anyone know what the deal is with the
    jest-pact
    library? At first glance, it looks like its getting frequent updates, but as far as I can tell it doesn't work with
    PactV4
    . I'm assuming then that I should be avoiding it? > https://github.com/pact-foundation/jest-pact
    m
    • 2
    • 2
  • e

    Emil

    07/22/2025, 6:20 AM
    Values from Provider State Good morning! I would likt to include provider state values in my TypeScript consumer's JSON body while preserving their original types (numbers, booleans, array, etc.). Pact-jvm's
    valueFromProviderState()
    works perfectly for this, but pact-js only has
    fromProviderState()
    which appears to be converting everything to strings, making the provider test fail. Is there a way to access provider state values in pact-js without string coercion, or is this feature planned? Thank you in advance!
    m
    r
    • 3
    • 17
  • s

    Slackbot

    08/22/2025, 10:49 AM
    This message was deleted.
    m
    • 2
    • 1
  • b

    boden winkel

    08/28/2025, 3:15 PM
    Hi, How to tackle testing enum in bi-directional approach ??? I have a consumer test like below which want to check one field of enum type. Consumer wiill have NEW OPEN values Imagine that provider contract (OAS spec file) contain enum which has one more additional value ie: NEW OPEN CLOSE. Once i trigger and publish this consumer test pact file to pactflow and run can i deploy against provider it saying that its compatible, which is kind of true as new value in provider should not break anything, however in a past there was situation that consumer was not able to deserialize that response due to new value. How to tackle this isue and break contract at can i deploy stage (i.e compare that with provider enum properly)
    b
    y
    m
    • 4
    • 4
  • b

    boden winkel

    09/03/2025, 12:33 PM
    Hi everyone! I have a antoher question 🙂 Is it possible to introduce contract testing for a third-party API when the provider doesn't offer an OpenAPI (OAS) schema that could serve as the contract ? In my case, the third-party API exposes a GraphQL schema: https://prismatic.io/docs/api/#prismatics-graphql-schema Are there any recommended techniques or patterns for applying contract testing in such scenarios—especially when using paid version of Pactflow? Would love to hear how others have approached similar challenges!
    b
    y
    • 3
    • 10
  • k

    Kieran McCarthy

    10/11/2025, 10:48 AM
    @Kieran McCarthy has left the channel
  • s

    SSh

    10/16/2025, 3:35 PM
    Hi. I looked documentation but didn't find answer for my question. What the behaviour should be for
    like
    matcher in case when it faced array inside object? Ex,:
    Copy code
    like({
      field1: "one",
      field2: 2,
      field3: [1, 2, 3],
    })
    or
    Copy code
    like({
      field1: "one",
      field2: 2,
      field3: [{f1: "ff", f2: 2}, {f1: "aa", f2: 5},{ f1: "dd", f2: 1},],
    })
    In https://docs.pact.io/implementation_guides/javascript/docs/matching I see next for
    like
    matcher
    Note that you can wrap a
    like
    around a single value or an object. When wrapped around an object, all values and child object values will be matched according to types, unless overridden by something more specific like a
    term
    .
    and for V3 matcher
    Applies the
    type
    matcher to value, which requires values to have the same type as the template
    Or I must explicitly declare
    eachLike
    for arrays in
    like
    section?
    y
    m
    • 3
    • 5
  • h

    Haiyang Huang

    11/20/2025, 10:12 AM
    Hello everyone! Does anyone have experience setting up a contract verification webhook in AWS? Our provider is a set of API endpoints which we deploy to AWS via cloudformation. We tried setting up an API endpoint (using AWS API Gateway) with a Lambda integration, but the pact-js verifier did not like running inside a Lambda. In the tracing logs, The Pact verifier connects to the broker and starts verification, but the Lambda function terminates with a Runtime.ExitError after ~1 second. The process appears to be cut off while fetching pacts from the broker. We are providing these npm packages to the lambda
    "@pact-foundation/pact-core": "^17.0.1",
    "@pact-foundation/pact-core-linux-x64-glibc": "^17.0.1",
    m
    • 2
    • 14
  • w

    Wojciech Wroblewski

    11/26/2025, 1:59 PM
    Hello all, I'm trying to use Verifier for provider. I configured it with
    Copy code
    describe('Pact Verification', () => {
        it('validates the expectations of Consumer', async () => {
            const opts = {
                provider: '{my}-example-provider',
                providerBaseUrl: '<http://localhost:3000>', // your service endpoint
                pactBrokerUrl: 'https://{my-url}.<http://pactflow.io/|pactflow.io/>',
                pactBrokerToken: '{my-token}',
                consumerVersionTags: ['main'],
    
            };
    
            await new Verifier(opts).verifyProvider();
        });
    });
    when running such a test I'm getting
    Copy code
    2025-11-26T13:51:47.013550Z  INFO ThreadId(11) pact_verifier::pact_broker: Fetching path '' from pact broker
    2025-11-26T13:51:47.809031Z ERROR ThreadId(11) pact_verifier: No pacts found for provider '{my}-example-provider' matching the given consumer version selectors in pact broker 'https://{my-url}.<http://pactflow.io/|pactflow.io/>': Link/Resource was not found - No pacts for provider '{my}-example-provider' were found in the pact broker. URL: 'https://{my-url}.<http://pactflow.io/|pactflow.io/>'
    2025-11-26T13:51:47.810401Z ERROR ThreadId(11) pact_verifier: Failed to load pact - No pacts found for provider '{my}-example-provider' matching the given consumer version selectors in pact broker 'https://{my-url}.<http://pactflow.io/|pactflow.io/>'
    2025-11-26T13:51:47.811140Z  WARN ThreadId(11) pact_matching::metrics:
    There are pacts published by consumer for given provider in my instance and I also double checked that tag name is proper. I'm not sure about that 'Fetching path '' ...' which is empty, but I'm not sure what's the path and how to set it What should I also check? Is there any option to improve verbosity or recommended debugging path?
    m
    • 2
    • 8
  • a

    Alan Boshier

    12/01/2025, 4:43 PM
    Hi - I'm struggling to understand how to use the
    eachKeyMatches
    matcher properly; the documentation here is terse, and I haven't been able to find any working examples out there that really do a good job of explaining it. Any pointers much appreciated TIA.
    y
    m
    • 3
    • 5
  • c

    Cody Jenkins

    12/09/2025, 12:35 AM
    Has anyone seen this before? Pact hangs when I make the body of my contract be
    {}
    . But if I remove the body or make it something else (e.g.
    {"foo":"bar"}
    ) then it does not hang 🧵 ✍️ EDIT: Yep it's #1602 again. Fix for me was to add:
    Copy code
    requestFilter: (req, _, next) => {
      delete req.headers['content-length'];
      next();
    },
    m
    • 2
    • 22
  • e

    Eoin K

    12/18/2025, 9:22 AM
    Hello all, we have been trying to build provider tests with the pact-js library but have a problem so thought to reach out. It appears the
    Verifier
    is unable to verify both synchronous and asynchronous contracts for a singular Provider. We can build a test solely for synchronous contracts using
    Verifier
    and solely for asynchronous contract using MessageProviderPact but using
    Verifier.messageProviders
    opt breaks those same verifications. We have created a example project to demonstrate. Does anyone have any experience of running asynchronous and synchronous side by side for one Provider? Any guidance would be appreciated In other languages it appears that people get around this by using filters such as Java however pact-js doesn't have this. Filtering upon interaction type would solve our problem and allow us to verify both asynchronous and synchronous contracts for one Provider under two test files. To explore a possible solution, I made changes to the pact-js library to introduce comparable filter functionality in this draft fork. This was supported by AI and I have not contributed to pact-js before so I would be open to discussion if this is the correct approach Thanks, Eoin : )
    đź‘‹ 1
    m
    • 2
    • 10
  • v

    Vaibhav Suryawanshi

    12/24/2025, 7:04 AM
    Hello everyone, 👋, I’ve been asked to create a working POC for contract testing using Pact in my organization, and I’d really appreciate guidance from the community on best practices for our scenario. Current System Landscape • 7 Micro Frontends (independent repos & deployments) • 10 Microservice Providers (independent repos & deployments) • Almost every frontend consumes most of the backend services • Teams are fully decoupled (separate CI/CD pipelines) Current Pact Setup (POC) • A separate QA-owned repository for contract testing • Consumer tests: -Pact consumer tests written in the QA repo -Requests are constructed manually (HTTP calls) -Verified only against the Pact mock server -No real frontend component or business logic involved • Provider tests: • Provider verification tests also live in the QA repo • Verified using: -In-memory DB -Fake/local server • Not verified against the actual deployed provider base URL This setup is technically working, but: • Contracts are not validated against real consumer logic • Providers are not verified using real provider runtime behavior • QA owns everything, but confidence feels limited • Core Concern > The contracts are being validated in isolation, not against the actual consumer and provider implementations. My Questions- 1. Is it possible (or recommended) to verify Pact contracts against real consumer and provider logic while keeping ownership with the QA team? 2. Are there any established patterns where: • Consumers remain untouched • Providers remain untouched • QA still owns contract definition and verification 3. Would approaches like: • Running provider verification against a real provider instance in a special “contract-test” mode • Using ephemeral environments / in-memory databases • Executing consumer tests through real frontend service layers be considered valid and scalable? 4. From a Pact philosophy perspective: • Is a QA-owned contract testing model like this anti-pattern, or • Is it acceptable as long as contracts are published and verified correctly? 5. In real-world micro-frontend + microservice ecosystems: • Who usually owns Pact tests? • How is trust maintained between teams?
    c
    • 2
    • 1