diff --git a/docs/_api-inspection/fundamentals.md b/docs/_api-inspection/fundamentals.md index f1552114..0e2a30fe 100644 --- a/docs/_api-inspection/fundamentals.md +++ b/docs/_api-inspection/fundamentals.md @@ -39,12 +39,14 @@ parameters: - 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` @@ -52,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 @@ -59,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 f3dbd5a6..cd6eb7f0 100644 --- a/docs/_api-lifecycle/flush.md +++ b/docs/_api-lifecycle/flush.md @@ -2,7 +2,7 @@ title: .flush(waitForBody) navTitle: '.flush()' position: 2 -versionAdded: 5.11.1 +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/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/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/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 21424767..99ffa98a 100644 --- a/docs/_api-mocking/mock.md +++ b/docs/_api-mocking/mock.md @@ -2,7 +2,7 @@ title: '.mock(matcher, response, options)' navTitle: .mock() position: 1 -versionAdded: "???" +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) @@ -14,6 +14,7 @@ description: | {: .warning} parameters: - name: matcher + versionAdded: 2.0.0 types: - String - Regex @@ -21,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 @@ -29,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_matcher.md b/docs/_api-mocking/mock_matcher.md index e41e1072..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 @@ -35,7 +37,7 @@ parameters: content: Match an exact url. Can be defined using a string or a `URL` instance - name: |- begin:... - versionAdded: 6.0.0 + versionAdded: 5.7.0 types: - String examples: @@ -44,6 +46,7 @@ parameters: content: Match a url beginning with a string - name: |- end:... + versionAdded: 5.7.0 types: - String examples: @@ -61,6 +64,7 @@ parameters: content: Match a url which has a given path - name: |- glob:... + versionAdded: 5.7.0 types: - String examples: @@ -69,6 +73,7 @@ parameters: content: Match a url using a glob pattern - name: |- express:... + versionAdded: 5.7.0 types: - String examples: @@ -78,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 @@ -95,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'}} @@ -104,6 +112,8 @@ 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 @@ -116,6 +126,7 @@ parameters: content: |- Use a function matcher, as described above - name: method + versionAdded: 2.1.0 types: - String content: |- @@ -123,6 +134,7 @@ parameters: examples: - get, POST - name: headers + versionAdded: 1.0.0 types: - Object - Headers @@ -150,6 +162,7 @@ parameters: - 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: |- @@ -158,6 +171,7 @@ parameters: - |- {"q": "cute+kittenz", "format": "gif"} - name: params + versionAdded: 6.0.0 types: - Object content: |- @@ -172,15 +186,18 @@ parameters: 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/` 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 ce97c164..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. @@ -22,12 +23,14 @@ parameters: 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 0b76a1dc..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,12 +55,14 @@ 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 @@ -68,6 +75,7 @@ parameters: 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: |- @@ -78,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 97708b03..c9278869 100644 --- a/docs/_api-mocking/spy.md +++ b/docs/_api-mocking/spy.md @@ -2,7 +2,7 @@ title: '.spy(matcher)' navTitle: .spy() position: 9 -versionAdded: "???ds" +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. diff --git a/docs/_includes/types.html b/docs/_includes/types.html index ab0f42ff..479c81d3 100644 --- a/docs/_includes/types.html +++ b/docs/_includes/types.html @@ -1,9 +1,7 @@ {{ include.block.name }} {% unless include.noVersion %} {% if include.block.name %} - {%if include.block.versionAdded %} - v{{include.block.versionAdded}} - {% endif %} + {% include version-added.html block=include.block %} {% endif %} {% endunless %}
@@ -16,13 +14,10 @@ {% unless include.noVersion %} - -{% unless include.block.name %} - {%if include.block.versionAdded %} - v{{include.block.versionAdded}} - {% endif %} - {% endunless %} + {% 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/_usage/configuration.md b/docs/_usage/configuration.md index 94b2b3ce..0de14dbb 100644 --- a/docs/_usage/configuration.md +++ b/docs/_usage/configuration.md @@ -11,18 +11,20 @@ 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: "???" + versionAdded: 6.5.0 versionAddedDetails: "'always' option added in v6.5.0" default: 'false' types: @@ -43,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 @@ -55,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: @@ -63,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 b8f1ea51..449db0c3 100644 --- a/docs/index.html +++ b/docs/index.html @@ -20,9 +20,8 @@

{% if doc.parentMethod %}  parameter for {{doc.parentMethod}}() {% endif %} - {%if doc.versionAdded %} - v{{doc.versionAdded}} - {% endif %} + {% include version-added.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');