From c742b39f20a8a13267db03b4d68607ff3ed06c9b Mon Sep 17 00:00:00 2001 From: Rhys Evans Date: Sat, 20 Jul 2024 13:44:49 +0100 Subject: [PATCH] docs: fix broken link --- docs/docs/@fetch-mock/core/configuration.md | 52 +++++++++++++++++++++ docs/docs/@fetch-mock/core/route/matcher.md | 2 +- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 docs/docs/@fetch-mock/core/configuration.md diff --git a/docs/docs/@fetch-mock/core/configuration.md b/docs/docs/@fetch-mock/core/configuration.md new file mode 100644 index 00000000..925c8e63 --- /dev/null +++ b/docs/docs/@fetch-mock/core/configuration.md @@ -0,0 +1,52 @@ +--- +sidebar_position: 6 +--- + +# Configuration + +On any `fetch-mock` instance, set configuration options directly on the `fetchMock.config` object. e.g. + +```js +const fetchMock = require('fetch-mock'); +fetchMock.config.sendAsJson = false; +``` + +## Available options + +Options marked with a `†` can also be overridden for individual calls to `.mock(matcher, response, options)` by setting as properties on the `options` parameter + +### sendAsJson + +`{Boolean}` default: `true` + +Always convert objects passed to `.mock()` to JSON strings before building reponses. Can be useful to set to `false` globally if e.g. dealing with a lot of `ArrayBuffer`s. When `true` the `Content-Type: application/json` header will also be set on each response. + +### includeContentLength + +`{Boolean}` default: `true` + +Sets a `Content-Length` header on each response. + +### matchPartialBody + +`{Boolean}` default: `false` + +Match calls that only partially match a specified body json. Uses the [is-subset](https://www.npmjs.com/package/is-subset) library under the hood, which implements behaviour the same as jest's [.objectContaining()](https://jestjs.io/docs/en/expect#expectobjectcontainingobject) method. + +### Custom fetch implementations + +`fetch`, `Headers`, `Request`, `Response` can all be set on the configuration object, allowing fetch-mock to mock any implementation of `fetch`, e.g. `node-fetch`. e.g. + +```js + +import { default as fetch, Headers, Request, Response } from 'node-fetch'; + +import fetchMock from 'fetch-mock'; + +fetchMock.config = Object.assign(fetchMock.config, { + Request, + Response, + Headers, + fetch, +}); +``` diff --git a/docs/docs/@fetch-mock/core/route/matcher.md b/docs/docs/@fetch-mock/core/route/matcher.md index 23626ce6..4f5c1b2f 100644 --- a/docs/docs/@fetch-mock/core/route/matcher.md +++ b/docs/docs/@fetch-mock/core/route/matcher.md @@ -126,7 +126,7 @@ When matching a body, this option ignores any properties not mentioned in the ma } ``` -This option can also be [set in the global configuration](/dummy) +This option can also be [set in the global configuration](/fetch-mock/docs/@fetch-mock/core/configuration) ## Function matchers