From 048b5b7209aaef2d2000c2728062a298dab05a4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Javier=20Cravero?= Date: Thu, 26 Nov 2015 13:23:48 +0000 Subject: [PATCH] chore: add ffetched to readme --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index 41d5dfd..eaa623b 100644 --- a/README.md +++ b/README.md @@ -87,3 +87,27 @@ Detaches farfetched from the global scope and restores the original function. ### `farfetched.clear(id)` Clears the handler with the given ID. + +## Streamlining the process for one request + +If you want to mock only one request and have a quick way to clean it up right before finishing your test as well as restoring fetch, you can use [ffetched](https://github.com/UXtemple/ffetched), e.g..: + +```js +import mockFetch from 'ffetched'; +import test from 'tape'; + +test('#fetch', t => { + const unmockFetch = mockFetch('/some-uri', { + data: 'back' + }); + + fetch('/some-uri').then(data => { + t.deepEquals(data, { + data: 'back' + }); + + unmockFetch(); + t.end(); + }); +}); +```