3 ms·
It's better for testing.
by ok123456 5y ago
It's better for testing.
- RussianCow 5y agoYou mean unit testing? How so? I have never seen unit tests make real HTTP requests; it's much better to mock them. And changing from async to sync code for unit tests sounds like a bad idea, since you're not testing your code the way it actually works in production.
- gwbas1c 5y agoThat's an unjustified excuse. The one thing that is consistent with UI programming among all platforms is that you never block the UI thread. You should be able to mock fetch/xmlhttprequest at any point, not just in your router. You should be able to mock those calls without needing to block the UI thread at runtime.
- ok123456 5y agoNo it's not. If you have to mock things like that it's a sign of poorly designed, stateful objects.