The extract adapter pattern makes asynchronous code easier to unit-test by isolating the asynchronous dependency behind a smaller adapter. Tests can replace that adapter with controlled, synchronous behavior instead of contacting the real dependency. section 6.2 section 6.2.2
Unlike extracting pure logic into test entry points, this pattern extracts the dependency itself. The adapter can also expose a simplified interface using the consumer’s terminology, hiding implementation complexity and limiting dependency changes to one module. section 6.2 section 6.2.2
Testing a website verifier
A network adapter hides fetching and returns { ok, text }. The website verifier consumes that interface, while a test supplies a fake returning illustrative content or unexpected content. The verifier can then test its success and failure decisions without relying on the network.
Figure 6.7 Wrapping the node-fetch module with our own network-adapter module helps us expose only the functionality our application needs, expressed in the language most suitable for the problem at hand.
The figure shows how wrapping node-fetch in a project-specific network adapter exposes only the functionality the application needs. section 6.2.2
