DiUS / pact-consumer-js-dsl

*DEPRECATED* A Javascript DSL for creating pacts, superceded by Pact JS
https://github.com/pact-foundation/pact-js
Other
56 stars 26 forks source link

How to verify the response content in async tests? #39

Closed moroshko closed 9 years ago

moroshko commented 9 years ago

Looking at this example, I wonder what is the point of specifying the body in .willRespondWith()?

Looks like the body is verified in the success function, and if this line is removed, the test passes (so the body that is specified in .willRespondWith() is basically ignored).

In other words, looks like I need to duplicate the expected response in 2 places:

Is there a way to avoid the duplication?

bethesque commented 9 years ago

The .willRespondWith() is required to be set to stub out the response, and to allow us verify (on the provider side) that the real response matches the actual response. If you took that out, the test would fail, because the client code would have no body to parse.

The expectation in success asserts that your consumer code has correctly handled the response.

Imagine a more complicated example where the document was parsed to a domain model that did not exactly correspond with the JSON, and it will make more sense.

moroshko commented 9 years ago

Thanks, makes sense now