Skip to content

Commit

Permalink
Merge pull request #758 from wheresrhys/rhys/docs-changes
Browse files Browse the repository at this point in the history
docs: add example
  • Loading branch information
wheresrhys authored Jul 26, 2024
2 parents 88b7ea8 + 0f381a9 commit 456806a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
18 changes: 18 additions & 0 deletions docs/docs/@fetch-mock/core/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

})
})

```
4 changes: 0 additions & 4 deletions docs/docs/@fetch-mock/core/mocking-and-spying.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 456806a

Please sign in to comment.