DEV Community

Discussion on: Testing NodeJs/Express API with Jest and Supertest

Collapse
 
avinash8686 profile image
avinash8686

There are no cases for api failure, It would be great if u add the failure cases as well, overall the post was pretty good and easy to understand.

Collapse
 
nedsoft profile image
Chinedu Orie

Yeah, that's true, I seemed to focus on the success side. I'll update it to take into account your feedback. Thank you.

Collapse
 
hotdangca profile image
James Robert Perih

You could:

expect(res.statusCode).toEqual(500);
Enter fullscreen mode Exit fullscreen mode

when you do something intentionally wrong, as well as:

expect(res.body).toEqual('Post not found');
Enter fullscreen mode Exit fullscreen mode

Various other uses of expect here

Collapse
 
nedsoft profile image
Chinedu Orie

Yeah, I've included some failure test cases in the sample project, I'd update the article to reflect it. Thanks for the hints.