Hello Folk, Is it possible to write a test on the ...
# general
p
Hello Folk, Is it possible to write a test on the 404 response? Test always fails, but pact file still genearte.
l
Yes in your test you can assert the expected response code. As long as the Pact verify and finalize is called this should work fine. The test shouldn't fail. As you are expecting a 404 response
☝️ 1
Feel free to share a code example
m
Usually, the issue is that your HTTP client throws an exception when you receive a 4xx or 5xx response. So Pact is returning the expected status code, but your test throws an error. Whatever language you use, you will need to make sure you catch that exception first
if you have example code we could advise more
Best to ask that in the language specific channel though e.g. #C9VBGLUM9
p
@Lewis Prescott @Matt (pactflow.io / pact-js / pact-go) OK, Thanks for you both. I will check my code and let you know again. I think it make sense.
👍 2
I was already checking the code no exception in my test code. Not sure can I share the code here? or should go to share on #C9W94PXPY?
👍 1
l
Yes share over there. I'm not too good with php myself
p
One more question, If it throws an exception like this. How can I handle the expectation? Do Pact have any expectation support throw an exception?
l
You can handle exceptions in your tests usually https://backendtea.com/post/phpunit-exception-test/
p
@Lewis Prescott Thank you. I understand the problem now 🙂
clear
😄 3