Relative Content

Tag Archive for expressaxiosjestjs

How to test a error using jest and axios?

I’ve been trying to test my API with jest and express. But I couldn’t figure out how to do it properly. I want to test validation while creating a user. And check what status code and response I got from the API too. But axios throws an error if API sends http 400 status code.
If I catch it and check the response from catch block I can’t seem to fail the test from try block if axios doesn’t throw the error (which means server validation failed and it returned 200 status code).