Howdy, I'm trying to write a
unit test for a TypeScript function that makes a couple of HTTP calls to an external service, and I'd like my test to assert that the calls are made in the right order with the right payload particularly because the second call content depends on the response of the first.
The function under test looks roughly like this. The first call gets a json object containing a pre-signed URL for the client to make a PUT request to.
As far as my understanding of the browser environment goes, fetch appears to be kinda built in and always there, so how can I get a handle on it to inject my own responses and assert on the call parameters?
The project this belongs to is using vitest. I have a similar question for calls made using the
openapi-fetch library but let's start with
fetch and stick with one question at a time.
Cheers, Tim