Good morning, could anyone help me to add more int...
# pact-js
r
Good morning, could anyone help me to add more interactions on consumer side? I've done according to example and it works with one interaction, but I cannot figure out the way to add more interactions 🤔
Copy code
beforeAll(() =>
    provider
      // Start the mock server
      .setup()
      // add interactions to the Mock Server, as many as required
      .then(() =>
        provider.addInteraction({
          state: 'I have employee details',
          uponReceiving: 'Request for employee details',
          withRequest: {
            method: 'GET',
            path: term({
              generate: 'employee/87034701-3046-47bc-9486-c470b04f66d7',
              matcher: 'employee/[A-Z0-9-]+',
            }),
          },
          willRespondWith: {
            status: 200,
            body: like(EXPECTED_BODY),
          },
        })
      )
  );
m
Which version are you on? Check the e2e example in the pact JS repo
You only call setup once for a pact session, addInteraction should be done once per test
r
Which version are you on?
"@pact-foundation/pact": "^9.18.1",
Ok looking into the e2e example 📖
👍 1
m
Cool. Make sure you check the 9.x.x branch and not the current stable as the API has changed subtly
r
Thanks it seems it is working. Interesting that I have to use beforeAll() and beforeEach() commands instead of before like in example 🤔 another question - one provider tests should be in one file? O can I update the pact file using different test files for the same provider?
b
some libs (e.g. jest-pact) abstract away those test-DSL concerns, if that makes it easier for you
how you break up your tests into files is up to you 🙂 But depending on what you want, you may have to do some manual work to tie the running order in with Pact
t
before is mocha, beforeAll is jest. Jest is significantly more popular than mocha now- it might be worth using it as the default in the examples
☝️ 1