Mock out HTTP traffic during a test, experimentally extracted from unexpected-mitm:
var httpception = ;var got = ;var assert = ;;
The http module will automatically be restored when the test ends. That
is detected by registering an
afterEach block and failing from that if
you have unexercised mocks.
If you think that involves too much magic, you can also pass a function as the last parameter. It will be invoked by httpception when the mocks are in place, and the mocks will be removed after it has exited. If the function returns a promise, the mocks will be kept until the promise has resolved:
When the test is done, the http module will automatically be restored, and the test will fail if there are unexercised mocks.