laika
laika copied to clipboard
Feature request: Provide a way to simulate network delay in mock responses
Use Case: I'd like to be able to write a test to simulate an async/delayed response from the GraphQL server. This would be similar to enabling "network throttling" in Dev Tools to test what happens when it takes a while for the server to respond, and would be useful for testing things like race conditions that pop up when certain queries finish before others.
Implementation Options
- Allow for returning a
Promise
from the ResultFn type. Laika waits for the Promise to resolve before returning the mocked result. - Allow for specifying a
delay
in the mock configuration, and Laika automatically handles making it async.
I think both options would be useful, honestly. The first one would be great for unit tests, so you could manually resolve the promise whenever you were ready vs. specifying an arbitrary amount of time. But, the second one would be nice for less boilerplate code when all you want is to make your test behave a little more like a real server.