Skip to content
Advertisement

How to store response body in supertest?

I am testing very basic REST api with supertest. I want to save the item id received in response body and assign it to a variable. Using this id i want to make further tests like get-item-by-id or update-item-by-id. No official documentation has covered this so a beginner friendly answer would be very helpful.

test i have written

JavaScript

Advertisement

Answer

Use regular JS variables

JavaScript

want to make further tests like get-item-by-id or update-item-by-id

You should explicitly test those endpoints, not via GET /api/products

E.g.

JavaScript

More importantly, don’t (or try not to) store variable state between tests.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement