```it('accepts a valid dog', () => { retu...
# pact-js
n
Copy code
it('accepts a valid dog', () => {
      return messagePact
        .given('a dog named drover')
        .expectsToReceive('a request for a dog')
        .withContent({
          id: like(1),
          name: like('drover'),
          type: term({
            generate: 'bulldog',
            matcher: '^(bulldog|sheepdog)$',
          }),
        })
        .withMetadata({
          queue: like('animals'),
        })
        .verify(synchronousBodyHandler(dogApiHandler));
    });
In this example, we have the
withContent
and
verify
property. What is the different between them? Did they both check the data we received from the producer?
m
withContent
sets up the mock data
verify
takes the user defined function (in this case, the
dogApiHandler
), passes it the contents of
withContent
(with matchers and other stuff removed) and checks that it doesn’t error/throw.
in other words,
verify
is the test
n
ohhh, so when we published this pact "contract" to pact broker, the provider must give the data that passed our test, right?
1
m
Bingo!
We abstract away the protocol, hence the indirection in the
verify
using this
synchronousBodyHandler
helper function (which just converts it to a sync function and passes the body contents straight through)
❤️ 1
n
thanks mate
bro got sick but still reply in a minute
🙏 1
+1 respect 😆
m
haha
I’m bored 😛
(Also my kids aren’t home yet after visiting grandparents for dinner 😛 )
😂 1