diff --git a/docs/_about/previous-versions.md b/docs/_about/previous-versions.md index ed09cda1..a1261c10 100644 --- a/docs/_about/previous-versions.md +++ b/docs/_about/previous-versions.md @@ -2,7 +2,7 @@ title: Previous versions position: 3 content_markdown: |- - v7, v8 & v9 are practically identical, only differing in their treatment of a few edge cases, or in compatibility with other libraries and environments. + v7, v8 & v9 are practically identical, only differing in their treatment of a few edge cases, or in compatibility with other libraries and environments. For clarity, each section of the documentation tells you which version a feature was added with a version label. For previous versions follow the documentation below: diff --git a/docs/_api-inspection/called.md b/docs/_api-inspection/called.md index 4789e582..1aff50dd 100644 --- a/docs/_api-inspection/called.md +++ b/docs/_api-inspection/called.md @@ -2,6 +2,7 @@ title: .called(filter, options) navTitle: .called() position: 1 +versionAdded: 1.0.0 description: |- Returns a Boolean indicating whether any calls to `fetch` matched the given `filter` and `options` --- diff --git a/docs/_api-inspection/calls.md b/docs/_api-inspection/calls.md index cc083ddb..016948c9 100644 --- a/docs/_api-inspection/calls.md +++ b/docs/_api-inspection/calls.md @@ -2,6 +2,7 @@ title: .calls(filter, options) navTitle: .calls() position: 2 +versionAdded: 1.0.0 description: |- Returns an array of all calls to fetch matching the given `filter` and `options`. Each call is returned as a `[url, options]` array. If `fetch` was called using a `Request` instance, the `url` and `options` will be inferred from it, and the original `Request` will be available as a `request` property on this array. --- diff --git a/docs/_api-inspection/done.md b/docs/_api-inspection/done.md index b98974e7..08f9098a 100644 --- a/docs/_api-inspection/done.md +++ b/docs/_api-inspection/done.md @@ -2,6 +2,7 @@ title: .done(filter) navTitle: .done() position: 6 +versionAdded: 5.3.0 description: |- Returns a Boolean indicating whether `fetch` was called the expected number of times (or has been called at least once if `repeat` is undefined for the route). It does not take into account whether the `fetches` completed successfully. parameters: diff --git a/docs/_api-inspection/fundamentals.md b/docs/_api-inspection/fundamentals.md index a07e95d2..0e2a30fe 100644 --- a/docs/_api-inspection/fundamentals.md +++ b/docs/_api-inspection/fundamentals.md @@ -13,11 +13,12 @@ parameters: options: - types: - undefined + versionAdded: 6.0.0 content: |- Retrieve all calls made to `fetch` - types: - true - - '"matched"' + versionAdded: 6.0.0 content: |- Retrieve all calls to `fetch` matched by some route defined by `fetch-mock`. The string `'matched'` can be used instead of `true` to make tests more readable examples: @@ -27,7 +28,7 @@ parameters: fetchMock.calls(MATCHED) - types: - false - - '"unmatched"' + versionAdded: 6.0.0 content: |- Retrieve all calls to `fetch` not matched by some route defined by `fetch-mock`. The string `'unmatched'` can be used instead of `false` to make tests more readable examples: @@ -35,11 +36,17 @@ parameters: const {UNMATCHED, fetchMock} = require('fetch-mock'); ... fetchMock.calls(UNMATCHED) + - types: + - '"matched"' + - '"unmatched"' + versionAdded: 9.0.0 + content: Aliases for `true` and `false` - name: routeIdentifier types: - String - RegExp - function + versionAdded: 2.0.0 content: |- All routes have an identifier: - If it's a [named route](#api-mockingmock_options), the identifier is the route's `name` @@ -47,6 +54,7 @@ parameters: All calls that were handled by the route with the given identifier will be retrieved - name: matcher + versionAdded: 7.0.0 types: - String - RegExp @@ -54,6 +62,7 @@ parameters: content: |- Any matcher compatible with the [mocking api](#api-mockingmock_matcher) can be passed in to filter the calls arbitrarily. The matcher will be executed using exactly the same rules as the mocking api - name: options + versionAdded: 7.0.0 types: - Object - String diff --git a/docs/_api-inspection/lastCall.md b/docs/_api-inspection/lastCall.md index 0b7afec4..7a687834 100644 --- a/docs/_api-inspection/lastCall.md +++ b/docs/_api-inspection/lastCall.md @@ -2,6 +2,7 @@ title: .lastCall(filter, options) navTitle: .lastCall() position: 3 +versionAdded: 4.0.0 description: |- Returns the arguments for the last call to `fetch` matching the given `filter` and `options`. The call is returned as a `[url, options]` array. If `fetch` was called using a `Request` instance, the `url` and `options` will be inferred from it, and the original `Request` will be available as a `request` property on this array. --- diff --git a/docs/_api-inspection/lastOptions.md b/docs/_api-inspection/lastOptions.md index 925188b9..e376794e 100644 --- a/docs/_api-inspection/lastOptions.md +++ b/docs/_api-inspection/lastOptions.md @@ -2,6 +2,7 @@ title: .lastOptions(filter, options) navTitle: .lastOptions() position: 5 +versionAdded: 4.0.0 description: |- Returns the options for the call to `fetch` matching the given `filter` and `options`. If `fetch` was last called using a `Request` instance, a set of `options` inferred from the `Request` will be returned --- diff --git a/docs/_api-inspection/lastUrl.md b/docs/_api-inspection/lastUrl.md index b2ae09b8..a8af477d 100644 --- a/docs/_api-inspection/lastUrl.md +++ b/docs/_api-inspection/lastUrl.md @@ -2,6 +2,7 @@ title: .lastUrl(filter, options) navTitle: .lastUrl() position: 4 +versionAdded: 4.0.0 description: |- Returns the url for the last call to `fetch` matching the given `filter` and `options`. If `fetch` was last called using a `Request` instance, the url will be inferred from this --- diff --git a/docs/_api-lifecycle/flush.md b/docs/_api-lifecycle/flush.md index 69fe2378..cd6eb7f0 100644 --- a/docs/_api-lifecycle/flush.md +++ b/docs/_api-lifecycle/flush.md @@ -2,6 +2,7 @@ title: .flush(waitForBody) navTitle: '.flush()' position: 2 +versionAdded: 5.11.0 description: |- Returns a `Promise` that resolves once all fetches handled by fetch-mock have resolved content_markdown: |- diff --git a/docs/_api-lifecycle/resetBehavior.md b/docs/_api-lifecycle/resetBehavior.md index d8409b6a..e911c84f 100644 --- a/docs/_api-lifecycle/resetBehavior.md +++ b/docs/_api-lifecycle/resetBehavior.md @@ -1,6 +1,7 @@ --- title: .resetBehavior() position: 5 +versionAdded: 7.0.0 description: |- Removes all mock routes from the instance of `fetch-mock`, and restores `fetch` to its original implementation if movcking globally. Will not clear data recorded for `fetch`'s calls. content_markdown: |- diff --git a/docs/_api-lifecycle/resetHistory.md b/docs/_api-lifecycle/resetHistory.md index 95b56c18..15d523d8 100644 --- a/docs/_api-lifecycle/resetHistory.md +++ b/docs/_api-lifecycle/resetHistory.md @@ -1,6 +1,7 @@ --- title: .resetHistory() position: 4 +versionAdded: 7.0.0 description: |- Clears all data recorded for `fetch`'s calls. It _will not_ restore fetch to its default implementation content_markdown: |- diff --git a/docs/_api-lifecycle/restore_reset.md b/docs/_api-lifecycle/restore_reset.md index 7be4f41a..5f10139e 100644 --- a/docs/_api-lifecycle/restore_reset.md +++ b/docs/_api-lifecycle/restore_reset.md @@ -2,6 +2,7 @@ title: .restore(), .reset() navTitle: .restore(), .reset() position: 3 +versionAdded: 7.0.0 description: |- Resets `fetch()` to its unstubbed state and clears all data recorded for its calls. `restore()` is an alias for `reset()` content_markdown: |- diff --git a/docs/_api-lifecycle/sandbox.md b/docs/_api-lifecycle/sandbox.md index bf45de7f..df2ff6be 100644 --- a/docs/_api-lifecycle/sandbox.md +++ b/docs/_api-lifecycle/sandbox.md @@ -1,6 +1,7 @@ --- title: '.sandbox()' position: 1.0 +versionAdded: 5.6.0 description: |- Returns a function that can be used as a drop-in replacement for `fetch`. Pass this into your mocking library of choice. The function returned by `sandbox()` has all the methods of `fetch-mock` exposed on it and maintains its own state independent of other instances, so tests can be run in parallel. left_code_blocks: diff --git a/docs/_api-mocking/_defaults.md b/docs/_api-mocking/_defaults.md deleted file mode 100644 index 4c3e1fc8..00000000 --- a/docs/_api-mocking/_defaults.md +++ /dev/null @@ -1,16 +0,0 @@ ---- -title: -position: -parameters: - - name: - content: -content_markdown: -left_code_blocks: - - code_block: - title: - language: -right_code_blocks: - - code_block: - title: - language: ---- diff --git a/docs/_api-mocking/add-matcher.md b/docs/_api-mocking/add-matcher.md index e549f775..1b46c84d 100644 --- a/docs/_api-mocking/add-matcher.md +++ b/docs/_api-mocking/add-matcher.md @@ -2,6 +2,7 @@ title: ".addMatcher({name, usesBody, matcher})" navTitle: .addMatcher() position: 1.9 +versionAdded: 9.3.0 description: |- Allows adding your own, reusable custom matchers to fetch-mock, for example a matcher for interacting with GraphQL queries, or an `isAuthorized` matcher that encapsulates the exact authorization conditions for the API you are mocking, and only requires a `true` or `false` to be input parentMethodGroup: mocking diff --git a/docs/_api-mocking/catch.md b/docs/_api-mocking/catch.md index 1ec49bd4..b968dea8 100644 --- a/docs/_api-mocking/catch.md +++ b/docs/_api-mocking/catch.md @@ -2,6 +2,7 @@ title: '.catch(response)' navTitle: .catch() position: 8 +versionAdded: 5.0.0 description: |- Specifies how to respond to calls to `fetch` that don't match any mocks. parentMethodGroup: mocking diff --git a/docs/_api-mocking/getAnyOnce_postAnyOnce.md b/docs/_api-mocking/getAnyOnce_postAnyOnce.md index f5387fa0..da47a37e 100644 --- a/docs/_api-mocking/getAnyOnce_postAnyOnce.md +++ b/docs/_api-mocking/getAnyOnce_postAnyOnce.md @@ -2,6 +2,7 @@ title: '.getAnyOnce(), .postAnyOnce(), .putAnyOnce(), .deleteAnyOnce(), .headAnyOnce(), .patchAnyOnce()' navTitle: .getAnyOnce(), .postAnyOnce() ... position: 7 +versionAdded: 9.2.0 description: |- Shorthands for `anyOnce()` that only respond to requests using a particular http method. parentMethodGroup: mocking diff --git a/docs/_api-mocking/getAny_postAny.md b/docs/_api-mocking/getAny_postAny.md index 73d1b202..d24ee04e 100644 --- a/docs/_api-mocking/getAny_postAny.md +++ b/docs/_api-mocking/getAny_postAny.md @@ -2,6 +2,7 @@ title: '.getAny(), .postAny(), .putAny(), .deleteAny(), .headAny(), .patchAny()' navTitle: .getAny(), .postAny() ... position: 5.5 +versionAdded: 9.2.0 description: |- Shorthands for `any()` that only respond to requests using a particular http method. parentMethodGroup: mocking diff --git a/docs/_api-mocking/getOnce_postOnce.md b/docs/_api-mocking/getOnce_postOnce.md index 55d27753..59114142 100644 --- a/docs/_api-mocking/getOnce_postOnce.md +++ b/docs/_api-mocking/getOnce_postOnce.md @@ -2,6 +2,7 @@ title: '.getOnce(), .postOnce(), .putOnce(), .deleteOnce(), .headOnce(), .patchOnce()' navTitle: .getOnce(), .postOnce() ... position: 4 +versionAdded: 5.3.0 description: |- Shorthands for `mock()` that create routes that only respond to requests using a particular http method, and that can only mock a single request. parentMethodGroup: mocking diff --git a/docs/_api-mocking/get_post.md b/docs/_api-mocking/get_post.md index f7b919a2..7fb4d9b9 100644 --- a/docs/_api-mocking/get_post.md +++ b/docs/_api-mocking/get_post.md @@ -2,6 +2,7 @@ title: '.get(), .post(), .put(), .delete(), .head(), .patch()' navTitle: .get(), .post() ... position: 2 +versionAdded: 5.0.0 description: |- Shorthands for `mock()` that create routes that only respond to requests using a particular http method. parentMethodGroup: mocking diff --git a/docs/_api-mocking/mock.md b/docs/_api-mocking/mock.md index 0d07f77f..99ffa98a 100644 --- a/docs/_api-mocking/mock.md +++ b/docs/_api-mocking/mock.md @@ -2,6 +2,8 @@ title: '.mock(matcher, response, options)' navTitle: .mock() position: 1 +versionAdded: 2.0.0 +versionAddedDetails: Callable with no arguments since v7.6.0 description: | Check out the new [cheatsheet](https://github.com/wheresrhys/fetch-mock/blob/master/docs/cheatsheet.md) {: .info} @@ -12,6 +14,7 @@ description: | {: .warning} parameters: - name: matcher + versionAdded: 2.0.0 types: - String - Regex @@ -19,6 +22,7 @@ parameters: - Object content: Criteria for which calls to `fetch` should match this route - name: response + versionAdded: 2.0.0 types: - String - Object @@ -27,6 +31,7 @@ parameters: - Response content: Response to send when a call is matched - name: options + versionAdded: 2.0.0 types: - Object content: More options to configure matching and responding behaviour diff --git a/docs/_api-mocking/mock_any.md b/docs/_api-mocking/mock_any.md index c220a40c..8a70b0d2 100644 --- a/docs/_api-mocking/mock_any.md +++ b/docs/_api-mocking/mock_any.md @@ -2,6 +2,7 @@ title: '.any(response, options)' navTitle: .any() position: 5 +versionAdded: 9.2.0 description: |- Shorthand for `mock()` which creates a route that will return a response to any fetch request. parentMethodGroup: mocking diff --git a/docs/_api-mocking/mock_any_once.md b/docs/_api-mocking/mock_any_once.md index d2b12cee..f73d658b 100644 --- a/docs/_api-mocking/mock_any_once.md +++ b/docs/_api-mocking/mock_any_once.md @@ -2,6 +2,7 @@ title: '.anyOnce(response, options)' navTitle: .anyOnce() position: 6 +versionAdded: 9.2.0 description: |- Shorthand for `mock()` which creates a route that will return a response to any single fetch request. parentMethodGroup: mocking diff --git a/docs/_api-mocking/mock_matcher.md b/docs/_api-mocking/mock_matcher.md index 2bd1bccc..df927dc4 100644 --- a/docs/_api-mocking/mock_matcher.md +++ b/docs/_api-mocking/mock_matcher.md @@ -1,6 +1,7 @@ --- title: 'matcher' position: 1.1 +versionAdded: 1.0.0 description: |- Criteria for deciding which requests to mock. @@ -18,6 +19,7 @@ parentMethod: mock parentMethodGroup: mocking parameters: - name: '*' + versionAdded: 5.0.0 types: - String content: Match any url @@ -27,12 +29,15 @@ parameters: types: - String - URL + versionAdded: 1.0.0 + versionAddedDetails: URL instances only supported since v8.1.0 examples: - |- "http://www.site.com/page.html" content: Match an exact url. Can be defined using a string or a `URL` instance - name: |- begin:... + versionAdded: 5.7.0 types: - String examples: @@ -41,6 +46,7 @@ parameters: content: Match a url beginning with a string - name: |- end:... + versionAdded: 5.7.0 types: - String examples: @@ -49,6 +55,7 @@ parameters: content: Match a url ending with a string - name: |- path:... + versionAdded: 7.0.0 types: - String examples: @@ -57,6 +64,7 @@ parameters: content: Match a url which has a given path - name: |- glob:... + versionAdded: 5.7.0 types: - String examples: @@ -65,6 +73,7 @@ parameters: content: Match a url using a glob pattern - name: |- express:... + versionAdded: 5.7.0 types: - String examples: @@ -74,12 +83,14 @@ parameters: Match a url that satisfies an [express style path](https://www.npmjs.com/package/path-to-regexp) - types: - RegExp + versionAdded: 1.0.0 examples: - |- /(article|post)\/\d+/ content: Match a url that satisfies a regular expression - types: - Function + versionAdded: 1.0.0 examples: - |- (url, {headers}) => !!headers.Authorization @@ -91,6 +102,7 @@ parameters: This can also be set as a `functionMatcher` in the [options parameter](#api-mockingmock_options), and in this way powerful arbitrary matching criteria can be combined with the ease of the declarative matching rules above. - types: - Object + versionAdded: 2.0.0 examples: - |- {url: 'end:/user/profile', headers: {Authorization: 'Basic 123'}} @@ -100,17 +112,21 @@ parameters: The url and function matchers described above can be combined with other criteria for matching a request by passing an an object which may have one or more of the properties described below. All these options can also be define on the third `options` parameters of the `mock()` method. options: - name: url + versionAdded: 8.3.0 + versionAddedDetails: Prior to v8.3.0 this was set using the (now deprecated) `matcher` property types: - String - RegExp content: |- Use any of the `String` or `RegExp` matchers described above. *Note that the property name 'matcher' can be used instead of 'url', but this is deprecated and support will be dropped in the next major version, so prefer to use 'url'* - name: functionMatcher + versionAdded: 7.3.0 types: - Function content: |- Use a function matcher, as described above - name: method + versionAdded: 2.1.0 types: - String content: |- @@ -118,6 +134,7 @@ parameters: examples: - get, POST - name: headers + versionAdded: 1.0.0 types: - Object - Headers @@ -129,6 +146,7 @@ parameters: - name: body types: - Object + versionAdded: 7.4.0 content: |- Match only requests that send a JSON body with the exact structure and properties as the one provided here. @@ -139,10 +157,12 @@ parameters: - |- { "key1": "value1", "key2": "value2" } - name: matchPartialBody + versionAdded: 9.1.0 types: - Boolean content: Match calls that only partially match a specified body json. See [global configuration](#usageconfiguration) for details. - name: query + versionAdded: 6.0.0 types: - Object content: |- @@ -151,6 +171,7 @@ parameters: - |- {"q": "cute+kittenz", "format": "gif"} - name: params + versionAdded: 6.0.0 types: - Object content: |- @@ -159,25 +180,32 @@ parameters: - |- {"section": "feed", "user": "geoff"} - name: repeat + versionAdded: 6.0.0 types: - Integer content: |- Limits the number of times the route can be used. If the route has already been called `repeat` times, the call to `fetch()` will fall through to be handled by any other routes defined (which may eventually result in an error if nothing matches it) - name: name + versionAdded: 1.0.0 types: - String content: |- A unique string naming the route. Used to subsequently retrieve references to the calls handled by it. Only needed for advanced use cases. - name: overwriteRoutes + versionAdded: 6.0.0 types: - Boolean content: See [global configuration](#usageconfiguration) - name: response + versionAdded: 2.0.0 content: Instead of defining the response as the second argument of `mock()`, it can be passed as a property on the first argument. See the [response documentation](#usageapimock_response) for valid values. content_markdown: |- Note that if using `end:` or an exact url matcher, fetch-mock ([for good reason](https://url.spec.whatwg.org/#url-equivalence)) is unable to distinguish whether URLs without a path end in a trailing slash or not i.e. `http://thing` is treated the same as `http://thing/` {: .warning} - If multiple mocks use the same `matcher` but use different options, such as `headers`, you will need to use the `overwriteRoutes: false` option. + If multiple mocks use the same `matcher` but use different options, such as `headers`, you will need to use the `overwriteRoutes: false` option. + {: .warning} + + Before v8.3.0 some of the options above had to be passed in as properties on a third parameter of `.mock()` {: .warning} --- diff --git a/docs/_api-mocking/mock_once.md b/docs/_api-mocking/mock_once.md index 6792cd7d..6a370b4f 100644 --- a/docs/_api-mocking/mock_once.md +++ b/docs/_api-mocking/mock_once.md @@ -1,6 +1,7 @@ --- title: '.once()' position: 3 +versionAdded: 5.3.0 description: |- Shorthand for `mock()` which creates a route that can only mock a single request. (see `repeat` option above) parentMethodGroup: mocking diff --git a/docs/_api-mocking/mock_options.md b/docs/_api-mocking/mock_options.md index 0c431333..42e4ce58 100644 --- a/docs/_api-mocking/mock_options.md +++ b/docs/_api-mocking/mock_options.md @@ -1,6 +1,7 @@ --- title: 'options' position: 1.3 +versionAdded: 5.0.0 description: |- An object containing further options for configuring mocking behaviour. @@ -16,17 +17,20 @@ parentMethodGroup: mocking parametersBlockTitle: Response options parameters: - name: delay + versionAdded: 7.7.0 types: - Integer content: |- Delays responding for the number of milliseconds specified. - name: sendAsJson + versionAdded: 4.1.0 default: true types: - Boolean content: See [global configuration](#usageconfiguration) - name: includeContentLength default: true + versionAdded: 5.13.0 types: - Boolean content: See [global configuration](#usageconfiguration) diff --git a/docs/_api-mocking/mock_response.md b/docs/_api-mocking/mock_response.md index 7a4cdf9d..6a495987 100644 --- a/docs/_api-mocking/mock_response.md +++ b/docs/_api-mocking/mock_response.md @@ -16,6 +16,7 @@ parentMethodGroup: mocking parameters: - types: - Response + versionAdded: 5.0.0 examples: - "new Response('ok', {status: 200})" content: | @@ -24,6 +25,7 @@ parameters: Note that it must use the same constructor as that used in the `fetch` implementation your application uses. [See how to configure this](#usagecustom-classes) - name: status code + versionAdded: 1.2.0 types: - Integer examples: @@ -31,16 +33,19 @@ parameters: content: Return a `Response` with the given status code. The response's `statusText` will also be set to the [default value corresponding to the status](https://fetch.spec.whatwg.org/#dom-response-statustext) - types: - String + versionAdded: 1.0.0 content: Return a 200 `Response` with the string as the response body examples: - Server responded ok - Bad Response - name: config + versionAdded: 1.0.0 types: - Object content: If an object *only* contains properties from among those listed below it is used to configure a `Response` to return options: - name: body + versionAdded: 1.0.0 types: - String - Object @@ -50,23 +55,27 @@ parameters: - Server responded ok - "{ token: 'abcdef' }" - name: status + versionAdded: 1.0.0 types: - Integer content: Set the `Response` status examples: - 200, 404, 503 - name: headers + versionAdded: 1.0.0 types: - Object content: Set the `Response` headers examples: - "{'Content-Type': 'text/html'}" - name: redirectUrl + versionAdded: 6.0.0 types: - String content: |- The url from which the `Response` should claim to originate from (to imitate followed directs). Will also set `redirected: true` on the response - name: throws + versionAdded: 1.0.0 types: - Error content: |- @@ -77,16 +86,19 @@ parameters: - Object - ArrayBuffer - ... + versionAdded: 1.0.0 content: |- If the `sendAsJson` option is set to `true`, any object that does not meet the criteria above will be converted to a `JSON` string and set as the response `body`. Otherwise, the object will be set as the response `body` (useful for `ArrayBuffer`s etc.) - types: - Promise + versionAdded: 4.2.0 content: |- A `Promise` that resolves to any of the options documented above examples: - 'new Promise(res => setTimeout(() => res(200), 50))' - types: - Function + versionAdded: 1.0.0 content: |- A function that returns any of the options documented above. The function will be passed the `url` and `options` `fetch` was called with. If `fetch` was called with a `Request` instance, it will be passed `url` and `options` inferred from the `Request` instance, with the original `Request` will be passed as a third argument. examples: diff --git a/docs/_api-mocking/spy.md b/docs/_api-mocking/spy.md index 694594cf..c9278869 100644 --- a/docs/_api-mocking/spy.md +++ b/docs/_api-mocking/spy.md @@ -2,6 +2,8 @@ title: '.spy(matcher)' navTitle: .spy() position: 9 +versionAdded: 5.5.0 +versionAddedDetails: Filtering by matcher added in v9.5.0 description: |- Records call history while passing each call on to `fetch` to be handled by the network. Optionally pass in a `matcher` to scope this to only matched calls, e.g. to fetch a specific resource from the network. parentMethodGroup: mocking diff --git a/docs/_includes/types.html b/docs/_includes/types.html index 3030c697..479c81d3 100644 --- a/docs/_includes/types.html +++ b/docs/_includes/types.html @@ -1,4 +1,9 @@ {{ include.block.name }} +{% unless include.noVersion %} + {% if include.block.name %} + {% include version-added.html block=include.block %} + {% endif %} +{% endunless %}
{% if include.block.types %} {% for type in include.block.types %} @@ -6,6 +11,13 @@ {% if forloop.last != true %}|{% endif %} {% endfor %} {% endif %} + + +{% unless include.noVersion %} + {% unless include.block.name %} + {% include version-added.html block=include.block %} + {% endunless %} +{% endunless %} {%if include.block.default %} [default {{ include.block.default}}] {% endif %} diff --git a/docs/_includes/version-added.html b/docs/_includes/version-added.html new file mode 100644 index 00000000..55416b70 --- /dev/null +++ b/docs/_includes/version-added.html @@ -0,0 +1,3 @@ +{%if include.block.versionAdded %} + v{{include.block.versionAdded}} +{% endif %} diff --git a/docs/_sass/_docs.scss b/docs/_sass/_docs.scss index d38aa231..c298dc81 100644 --- a/docs/_sass/_docs.scss +++ b/docs/_sass/_docs.scss @@ -92,6 +92,18 @@ dt code { font-family: monospace; } +.version-added { + font-weight: normal; + background: #fafafa; + border: 1px solid #00994D; + border-radius: 2px; + color: #00994D; + display: inline-block; + padding: 0 4px; + font-size: 0.6em; + vertical-align: text-bottom; +} + .types-zone code { font-family: monospace; font-weight: bold; diff --git a/docs/_usage/configuration.md b/docs/_usage/configuration.md index 72193a9b..0de14dbb 100644 --- a/docs/_usage/configuration.md +++ b/docs/_usage/configuration.md @@ -1,6 +1,7 @@ --- title: Configuration position: 7 +versionAdded: 6.0.0 description: |- On any `fetch-mock` instance, set configuration options directly on the `fetchMock.config` object. e.g. ```js @@ -10,17 +11,21 @@ description: |- parametersBlockTitle: Options parameters: - name: sendAsJson + versionAdded: 4.1.0 default: true types: - Boolean content: |- 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. - name: includeContentLength + versionAdded: 5.13.0 default: true types: - Boolean content: Sets a `Content-Length` header on each response. - name: fallbackToNetwork + versionAdded: 6.5.0 + versionAddedDetails: "'always' option added in v6.5.0" default: 'false' types: - Boolean @@ -31,6 +36,7 @@ parameters: - `'always'`: All calls fall through to the network, effectively disabling fetch-mock. - name: overwriteRoutes default: 'undefined' + versionAdded: 6.0.0 types: - Boolean content: |- @@ -39,10 +45,12 @@ parameters: - `true`: Overwrites the existing route - `false`: Appends the new route to the list of routes - name: matchPartialBody + versionAdded: 9.1.0 types: - Boolean content: 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 [.objectContainig()](https://jestjs.io/docs/en/expect#expectobjectcontainingobject) method. - name: warnOnFallback + versionAdded: 6.0.0 default: true types: - Boolean @@ -51,6 +59,7 @@ parameters: - name: Promise types: - Constructor + versionAdded: 5.9.0 content: A custom `Promise` constructor, if your application uses one - name: fetch types: @@ -59,14 +68,17 @@ parameters: - name: Headers types: - Constructor + versionAdded: 5.9.0 content: The `Headers` constructor of a custom `fetch` implementation, if your application uses one - name: Request types: - Constructor + versionAdded: 5.9.0 content: The `Request` constructor of a custom `fetch` implementation, if your application uses one - name: Response types: - Constructor + versionAdded: 5.0.0 content: The `Response` constructor of a custom `fetch` implementation, if your application uses one content_markdown: |- diff --git a/docs/_usage/custom-classes.md b/docs/_usage/custom-classes.md index de4f32d2..68039422 100644 --- a/docs/_usage/custom-classes.md +++ b/docs/_usage/custom-classes.md @@ -2,6 +2,7 @@ title: Custom subclasses position: 6 parentItem: installation +versionAdded: 5.9.0 content_markdown: |- `fetch-mock` uses `Request`, `Response` and `Headers` constructors internally, and obtains these from `node-fetch` in Node.js, or `window` in the browser. If you are using an alternative implementation of `fetch` you will need to configure `fetch-mock` to use its implementations of these constructors instead. These should be set on the `fetchMock.config` object, e.g. diff --git a/docs/cheatsheet.md b/docs/cheatsheet.md index 5d4d0696..b54d8272 100644 --- a/docs/cheatsheet.md +++ b/docs/cheatsheet.md @@ -63,7 +63,7 @@ The following request would be matched by all the mocks described below: fetch('http://example.com/users/bob?q=rita', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: '{"prop1": "val1", "prop2": "val2"}', + body: '{"prop1": "val1", "prop2": "val2"}' }); ``` diff --git a/docs/index.html b/docs/index.html index 4b803353..449db0c3 100644 --- a/docs/index.html +++ b/docs/index.html @@ -20,9 +20,10 @@

{% if doc.parentMethod %}  parameter for {{doc.parentMethod}}() {% endif %} + {% include version-added.html block=doc %}

- {% include types.html block=doc %} + {% include types.html block=doc noVersion=true %} {% if doc.description %}

diff --git a/docs/v6-v7-upgrade-guide.md b/docs/v6-v7-upgrade-guide.md index 2d8f7652..a2233a61 100644 --- a/docs/v6-v7-upgrade-guide.md +++ b/docs/v6-v7-upgrade-guide.md @@ -99,7 +99,7 @@ Read more in the [filtering docs](http://www.wheresrhys.co.uk/fetch-mock/#api-in fetchMock.mock('*', 200); await fetch('/main-course/lasagne', { method: 'POST', - headers: { discount: true }, + headers: { discount: true } }); await fetch('/main-course/bolognaise');