hey guys, normally the mockServer variable is inst...
# pact-js
i
hey guys, normally the mockServer variable is instantiated during test execution e.g.
Copy code
it('Domain exists - Responding with the correct companyId for specific domain', () => {
       // setup provider
       ....
      return provider.executeTest(async (mockServer: V3MockServer) => {
        // call function which takes in 'mockServer' as a param

        // test assertion here
      });
    });
and the only way to pass the
mockServer
var is within
provider.executeTest()
, but how can i set
mockServer
in a before block before the it() block? because it would say that
mockServer
is not defined
blobwave 1
the test above uses PactV3 by the way: import { V3MockServer } from ‘@pact-foundation/pact/src/v3/matchers’; import { PactV3 } from ’@pact-foundation/pact
y
It’s only instantiated in the executeTest block
what are you trying to do?
i
tried installing
jest-pact
which provides a wrapper for me to wrap the entire test with
Copy code
pactWith({ provider object}, () => {

// ...

}
and this is using
Copy code
import { pactWith } from 'jest-pact/dist/v3';
import { V3MockServer } from '@pact-foundation/pact/src/v3/matchers';
to force it to use PactV3 (in theory) So this will allow me to define the mockServer var in a before() block, however when i do this :
Copy code
pactWith(
  {
    dir: //..
    consumer: //.. 
    provider: //..
    logLevel: 'debug',
  },
  (interaction) => {
    interaction('hit api', ({ provider, execute }) => {
       //....
          functionCall( provider.mockServer),
          });
       

 // tests below
....
it says
Copy code
Property 'mockServer' does not exist on type 'PactV3'.ts(2339)
why is that?
y
I’d need to create a repro or check the source. jest-pact was a convenience wrapper originally created to deal with the pact core (provided by a ruby cli)’s lifecycle methods. pact-js v10+ uses the pact-core (provided by the rust ffi) and doesn’t require the same lifecycle management. The dsl was never fully finalised in
jest-pact
and the authoring experience is pretty nice now with vanilla
pact-js
I’ve never gone back and done anything with
jest-pact
https://github.com/pact-foundation/jest-pact/issues/215
Couple of options 1. Use Pact-js directly 2. Raise an issue against jest-pact, along with a repro of what you are trying to do. a. for extra mega bonus points, feel free to raise a PR 🙂
i
for 1) do you mean not use (jest-pact) pactWith() wrapper? 2) yep thanks will see 🙂
t
The mock server doesn't exist on the types that the v3 pactWith wrapper provides. The v3 pactWith wrapper was written before the DSL was finalised, and was pretty beta at the time. I'm not sure how useful you'll find it
The history of jest-pact is that it was originally boilerplate to set better defaults - it would have been rolled in to pact, but we couldn't because pact doesn't require jest