Skip to content

Commit

Permalink
midway through documenting which versions a feature was added in
Browse files Browse the repository at this point in the history
  • Loading branch information
wheresrhys committed May 9, 2020
1 parent 2a9066c commit d0ce202
Show file tree
Hide file tree
Showing 22 changed files with 74 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/_about/previous-versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <small class="version-added">version</small> label.
For previous versions follow the documentation below:
Expand Down
1 change: 1 addition & 0 deletions docs/_api-inspection/called.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
---
1 change: 1 addition & 0 deletions docs/_api-inspection/calls.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
---
1 change: 1 addition & 0 deletions docs/_api-inspection/done.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 7 additions & 2 deletions docs/_api-inspection/fundamentals.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -27,14 +28,18 @@ 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:
- |-
const {UNMATCHED, fetchMock} = require('fetch-mock');
...
fetchMock.calls(UNMATCHED)
- types:
- '"matched"'
- '"unmatched"'
content: Aliases for `true` and `false`
- name: routeIdentifier
types:
- String
Expand Down
1 change: 1 addition & 0 deletions docs/_api-lifecycle/flush.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
title: .flush(waitForBody)
navTitle: '.flush()'
position: 2
versionAdded: 5.11.1
description: |-
Returns a `Promise` that resolves once all fetches handled by fetch-mock have resolved
content_markdown: |-
Expand Down
1 change: 1 addition & 0 deletions docs/_api-lifecycle/restore_reset.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: |-
Expand Down
1 change: 1 addition & 0 deletions docs/_api-mocking/add-matcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/_api-mocking/getAnyOnce_postAnyOnce.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/_api-mocking/getAny_postAny.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/_api-mocking/getOnce_postOnce.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions docs/_api-mocking/mock.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: '.mock(matcher, response, options)'
navTitle: .mock()
position: 1
versionAdded: "???"
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}
Expand Down
1 change: 1 addition & 0 deletions docs/_api-mocking/mock_any.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/_api-mocking/mock_any_once.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion docs/_api-mocking/mock_matcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,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: 6.0.0
types:
- String
examples:
Expand All @@ -49,6 +52,7 @@ parameters:
content: Match a url ending with a string
- name: |-
path:...
versionAdded: 7.0.0
types:
- String
examples:
Expand Down Expand Up @@ -106,6 +110,7 @@ parameters:
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: |-
Expand All @@ -129,6 +134,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.
Expand All @@ -139,6 +145,7 @@ 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.
Expand All @@ -159,6 +166,7 @@ parameters:
- |-
{"section": "feed", "user": "geoff"}
- name: repeat
versionAdded: 6.0.0
types:
- Integer
content: |-
Expand All @@ -178,6 +186,9 @@ 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}
---
1 change: 1 addition & 0 deletions docs/_api-mocking/mock_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ parentMethodGroup: mocking
parametersBlockTitle: Response options
parameters:
- name: delay
versionAdded: 7.7.0
types:
- Integer
content: |-
Expand Down
1 change: 1 addition & 0 deletions docs/_api-mocking/mock_response.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ parameters:
examples:
- "{'Content-Type': 'text/html'}"
- name: redirectUrl
versionAdded: 6.0.0
types:
- String
content: |-
Expand Down
2 changes: 2 additions & 0 deletions docs/_api-mocking/spy.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: '.spy(matcher)'
navTitle: .spy()
position: 9
versionAdded: "???ds"
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
Expand Down
17 changes: 17 additions & 0 deletions docs/_includes/types.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
{{ include.block.name }}
{% unless include.noVersion %}
{% if include.block.name %}
{%if include.block.versionAdded %}
<small class="version-added" title="Added in version {{include.block.versionAdded}}{%if include.block.versionAddedDetails %}{{include.block.versionAddedDetails}}{% endif %}">v{{include.block.versionAdded}}</small>
{% endif %}
{% endif %}
{% endunless %}
<div class="types-zone">
{% if include.block.types %}
{% for type in include.block.types %}
<code{% unless include.block.name %} class="name"{% endunless %}>{{type}}</code>
{% if forloop.last != true %}|{% endif %}
{% endfor %}
{% endif %}


{% unless include.noVersion %}

{% unless include.block.name %}
{%if include.block.versionAdded %}
<small class="version-added" title="Added in version {{include.block.versionAdded}}{%if include.block.versionAddedDetails %}{{include.block.versionAddedDetails}}{% endif %}">v{{include.block.versionAdded}}</small>
{% endif %}
{% endunless %}
{% endunless %}
{%if include.block.default %}
<span class="default">[default&nbsp;<code>{{ include.block.default}}</code>]</span>
{% endif %}
Expand Down
12 changes: 12 additions & 0 deletions docs/_sass/_docs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions docs/_usage/configuration.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -21,6 +22,8 @@ parameters:
- Boolean
content: Sets a `Content-Length` header on each response.
- name: fallbackToNetwork
versionAdded: "???"
versionAddedDetails: "'always' option added in v6.5.0"
default: 'false'
types:
- Boolean
Expand All @@ -31,6 +34,7 @@ parameters:
- `'always'`: All calls fall through to the network, effectively disabling fetch-mock.
- name: overwriteRoutes<sup>†</sup>
default: 'undefined'
versionAdded: 6.0.0
types:
- Boolean
content: |-
Expand Down
6 changes: 4 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ <h3>
{% if doc.parentMethod %}
&nbsp;<span class="endpoint">parameter for <a href="#api-{{doc.parentMethodGroup}}{{doc.parentMethod}}">{{doc.parentMethod}}()</a></span>
{% endif %}

{%if doc.versionAdded %}
<small class="version-added" title="Added in version {{doc.versionAdded}}{%if doc.versionAddedDetails %}. {{doc.versionAddedDetails}}{% endif %}">v{{doc.versionAdded}}</small>
{% endif %}
</h3>
{% include types.html block=doc %}
{% include types.html block=doc noVersion=true %}
{% if doc.description %}
<p class="description">

Expand Down

0 comments on commit d0ce202

Please sign in to comment.