When creating applications and libraries that communicate over the network, you usually want to stub out or otherwise replace the network calls with some canned responses. While module mocking works, it often couples your test code to the particular network abstraction you’ve chosen. And setting up a full test server for every test is often slow, especially if you want to set it up fresh for every single test. To address this problem, Jest should support mocking out at the low level network layer via a dedicated API. Doing so would allow deep integration into reporters and watch plugins, allowing the user to for example record some real requests, and have Jest store them on disk for later use.
Deliverables
[ ] Implement low-level stubbing of http
[ ] Implement high-level API for setting up canned responses
[ ] Implement some way of recording real requests/responses and storing them to disk
TODO
[ ] Research what APIs/module exist for this problem space today
Summary
When creating applications and libraries that communicate over the network, you usually want to stub out or otherwise replace the network calls with some canned responses. While module mocking works, it often couples your test code to the particular network abstraction you’ve chosen. And setting up a full test server for every test is often slow, especially if you want to set it up fresh for every single test. To address this problem, Jest should support mocking out at the low level network layer via a dedicated API. Doing so would allow deep integration into reporters and watch plugins, allowing the user to for example record some real requests, and have Jest store them on disk for later use.
Deliverables
TODO
Test Plan
TBD
References
https://github.com/facebook/jest/issues/6081