fetch-mock
fetch-mock copied to clipboard
Move delay and repeat onto the response object
They fit well there. Well, delay definitely does. not sure about repeat
I would argue that delay is telling the server (in this case a mocked server) to delay sending the response. The response itself has no control over, or concept of, when it is sent. Same with repeat. We are telling the server how many times to respond to a given route. The response is just an object describing what the server should respond with, and should never be concerned about implementation details at the server level. Especially considering that a raw Response instance is a valid response object, the current implementation makes the most sense, IMO.
The current implementation would still be supported (under the hood the options all get smooshed together anyway), but I see the API more as
- parameter 1 - decide which requests to respond to
- parameter 2 - decide how to respond to them -parameter 3 - stuff which feels awkward in both 1 and 2
Another argument for putting delay in 2 is because - until fairly recently - it didn't exist as an option and the only way to delay responses was with either a promise or a function, both of which sit squarely in parameter 2. So delaying responses has historically been a second parameter concern
Thanks for sharing your opinion though - interested to hear it