NGUYEN HOANG MINH CHAU
08/07/2024, 8:32 AMit('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?Matt (pactflow.io / pact-js / pact-go)
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.Matt (pactflow.io / pact-js / pact-go)
verify is the testNGUYEN HOANG MINH CHAU
08/07/2024, 8:45 AMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
verify using this synchronousBodyHandler helper function (which just converts it to a sync function and passes the body contents straight through)NGUYEN HOANG MINH CHAU
08/07/2024, 8:48 AMNGUYEN HOANG MINH CHAU
08/07/2024, 8:48 AMNGUYEN HOANG MINH CHAU
08/07/2024, 8:48 AMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)