elm-program-test icon indicating copy to clipboard operation
elm-program-test copied to clipboard

Improve documentation for simulateHttpResponseAdvanced

Open avh4 opened this issue 2 years ago • 0 comments

People don't understand what the Int parameter means.

My explanation answering a slack thread:

it’s the index of which request in the queue for that method/URL to handle, so if you have 4 to the same method/URL that are all still pending, then you can choose 1, 2, 3, or 4 as the one to resolve. Note that if you made multiple of those requests at the same moment (in the same batch of effects), then there might be little trial and error to figure out what order they got put into the queue in. Also note that you only need that if the simultaneous requests were made to the same URL and HTTP method. If they were all to different URLs and/or methods, then you can just use the normal simulateHttpResponse

Also, when a request is resolved, it's no longer in the queue, so if you had 4 and resolved one of them, then there would only be 3 immediately after.

Also, it's safe to use the normal simulateHttpResponse if you're unsure, since the error message will tell you if you need to use simulateHttpResponseAdvanced.

It would probably be good to explain an example of one or more scenarios.

The goals for the docs here should be:

  • Make it clear when you don't need simulateHttpResponseAdvanced (and what to prefer instead)
  • Clearly explain how to use it when needed
  • Be as concise as possible while fulfilling the other goals.

avh4 avatar Jun 02 '22 18:06 avh4