From 3355b665163fbf4c58aa34793d5f9c7e4c91ac7c Mon Sep 17 00:00:00 2001 From: Rhys Evans Date: Tue, 3 Dec 2024 15:04:05 +0000 Subject: [PATCH] docs: added more docs on how methods no longer mock fetch by default --- docs/docs/API/more-routing-methods.md | 2 ++ docs/docs/Usage/upgrade-guide.md | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/docs/docs/API/more-routing-methods.md b/docs/docs/API/more-routing-methods.md index 5ebca9ca..aea510a5 100644 --- a/docs/docs/API/more-routing-methods.md +++ b/docs/docs/API/more-routing-methods.md @@ -7,6 +7,8 @@ sidebar_label: More routing methods These methods allow defining routes for common use cases while avoiding writing hard to read configuration objects. They all return the fetchMock instance, and are therefor chainable. Unless noted otherwise, each of the methods below have the same signature as `.route()`. +> Note that in older versions of fetch-mock these methods woudl also replace global `fetch` with your mock. From version 12 onwards this is no longer the case, and you will need to start your tests with `fetchMock.mockGlobal()` or similar. [Read the mocking and spying docs](/fetch-mock/docs/API/mocking-and-spying). + ## .catch() `.catch(response)` diff --git a/docs/docs/Usage/upgrade-guide.md b/docs/docs/Usage/upgrade-guide.md index e1096e6b..e2528ba7 100644 --- a/docs/docs/Usage/upgrade-guide.md +++ b/docs/docs/Usage/upgrade-guide.md @@ -16,6 +16,10 @@ Previously this was true in browsers, but in node.js the node-fetch library was This combined adding a route with mocking the global instance of `fetch`. These are now split into 2 methods: `.route()` and `.mockGlobal()`. +### Routing convenience methods no longer mock `fetch` + +Similar to the last point, `.once()`, `.get()`, `.post()`, `getOnce()`, `postOnce()` and all other routing convenience methods no longer mock the global instance of `fetch`, and you will need to call `.mockGlobal()` explicitly. + ### Reset methods changed `.reset()`, `.restore()`, `.resetBehavior()` and `.resetHistory()` have been removed and replaced with [methods that are more granular and clearly named](/fetch-mock/docs/API/resetting). Note that the [jest](/fetch-mock/docs/wrappers/jest) and [vitest](/fetch-mock/docs/wrappers/vitest) wrappers for fetch-mock still implement `.mockClear()`, `mockReset()` and `mockRestore()`.