vendredi 7 février 2020

How to assert that app sends correct data to API server with POST request

I am writing React.js application talking to API server. I have read tons of articles on how to mock these calls and send some fake response from API. I can do testing using @testing-library/react, I can easily mock axios with axios-mock-adapter and test fetch requests using HTTP GET method. But I cannot find anywhere how to make sure that my app, when it sends some POST request, sends correct data to API, i.e. that my app sends json payload with e.g. "id" field, or "name" field set to "abc", or something like this. I am new to React.js. Please advice how to make tests asserting what the app sends to API.

Aucun commentaire:

Enregistrer un commentaire