From 0f381a9cbb4309e412095a86963097f48bfcdd2a Mon Sep 17 00:00:00 2001 From: Rhys Evans Date: Fri, 26 Jul 2024 21:21:53 +0100 Subject: [PATCH] docs: add example --- docs/docs/@fetch-mock/core/index.md | 18 ++++++++++++++++++ .../@fetch-mock/core/mocking-and-spying.md | 4 ---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/docs/docs/@fetch-mock/core/index.md b/docs/docs/@fetch-mock/core/index.md index 101d9976d..642e91ff1 100644 --- a/docs/docs/@fetch-mock/core/index.md +++ b/docs/docs/@fetch-mock/core/index.md @@ -12,3 +12,21 @@ This library implements three main features 3. Some low level APIs for accessing the call history of `fetchHandler` (these are not intended for direct use by the developer, but expose enough information for other libraries, such as `@fetch-mock/jest`, to provide more user friendly APIs built on top of this low level functionality). `@fetch-mock/core` is not intended for direct use in tests. It **DOES NOT** actually replace your `fetch` implementation with `fetchHandler`; this is left to wrapper libraries such as `@fetch-mock/jest`. This is because different testing frameworks have different opinions about this behaviour, and this core library deliberately avoids making decisions likely to clash with other tools in your testing toolchain, so that the `fetchHandler` implementation is more portable. + +```js +import fetchMock from '@fetch-mock/core'; +describe('myModule', () => { + beforeEach(() => fetchMock.mockGlobal()) + + it('gets user data from the api endpoint', async () => { + fetchMock.route({ + express: '/api/users/:user' + expressParams: {user: 'kenneth'} + }, {userData: {}}, 'userDataFetch') + await myModule.initialiseUserPage({user: 'kenneth'}) + expect(fetchMock.called('userDataFetch')) + + }) +}) + +``` diff --git a/docs/docs/@fetch-mock/core/mocking-and-spying.md b/docs/docs/@fetch-mock/core/mocking-and-spying.md index 8c9efa441..26f023786 100644 --- a/docs/docs/@fetch-mock/core/mocking-and-spying.md +++ b/docs/docs/@fetch-mock/core/mocking-and-spying.md @@ -8,10 +8,6 @@ These methods allow mocking or spying on the `fetch` implementation used by your Note that these methods are only implemented in `@fetch-mock/core` and are not avilable when using `@fetch-mock/jest`, `@fetch-mock/vitest` etc.... Those libraries provide ways to mock `fetch` that are more idiomatic to their own ecosystem. -Wrapper around @fetch-mock/core that implements mocking of global fetch, including spying on and falling through to the native fetch implementation. - -In addition to the @fetch-mock/core API its methods are: - ## When using global fetch in your application ### mockGlobal()