What should I do with my first test? #831
-
I've got the following test with pact:
I'm sitting here wondering, isn't that test alone completely useless? I mean I tell pact what I expect as a response and voila I get exactly that. I copied that example from pact-jest and changed it a bit. Do I have to add more tests in |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
If you just write consumer tests, you will be marking your own exam. The key value from pact is confirming that the consumer and the provider speak the same language. This means you should use the contract that your consumer tests generate to validate your provider. You definitely don’t need to confirm that your front end components are rendered - pact is for your API layer. I would recommend reading the “how pact works” documentation. |
Beta Was this translation helpful? Give feedback.
-
The way I like to think about writing a Pact test, is that I'm going to write a unit test of my API client. It just so happens, that by using Pact it will capture a contract I can use to later verify that the mocks were correct. i.e. the mocks are validated. So, asserting that my API client received an HTTP 200 is not very useful (because Pact will do that for you). What is important to check, is that your API client did the right thing with the response. It's common in JS to simply pass the JSON blob that came back from the API client. If that's the case, then a Pact test won't need much else. It's also common to convert the JSON into a domain model. In your case |
Beta Was this translation helpful? Give feedback.
The way I like to think about writing a Pact test, is that I'm going to write a unit test of my API client. It just so happens, that by using Pact it will capture a contract I can use to later verify that the mocks were correct. i.e. the mocks are validated.
So, asserting that my API client received an HTTP 200 is not very useful (because Pact will do that for you). What is important to check, is that your API client did t…