Skip to content

Commit

Permalink
finish documenting versions features were added
Browse files Browse the repository at this point in the history
  • Loading branch information
wheresrhys committed May 10, 2020
1 parent d0ce202 commit b2cf53c
Show file tree
Hide file tree
Showing 24 changed files with 72 additions and 35 deletions.
4 changes: 4 additions & 0 deletions docs/_api-inspection/fundamentals.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,30 @@ 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`
- If the route is unnamed, the identifier is the value of the `matcher` argument that was passed in to `.mock()`
All calls that were handled by the route with the given identifier will be retrieved
- name: matcher
versionAdded: 7.0.0
types:
- String
- RegExp
- function
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
Expand Down
1 change: 1 addition & 0 deletions docs/_api-inspection/lastCall.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
---
1 change: 1 addition & 0 deletions docs/_api-inspection/lastOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---
1 change: 1 addition & 0 deletions docs/_api-inspection/lastUrl.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---
2 changes: 1 addition & 1 deletion docs/_api-lifecycle/flush.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: |-
Expand Down
1 change: 1 addition & 0 deletions docs/_api-lifecycle/resetBehavior.md
Original file line number Diff line number Diff line change
@@ -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: |-
Expand Down
1 change: 1 addition & 0 deletions docs/_api-lifecycle/resetHistory.md
Original file line number Diff line number Diff line change
@@ -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: |-
Expand Down
1 change: 1 addition & 0 deletions docs/_api-lifecycle/sandbox.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
16 changes: 0 additions & 16 deletions docs/_api-mocking/_defaults.md

This file was deleted.

1 change: 1 addition & 0 deletions docs/_api-mocking/catch.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/_api-mocking/get_post.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion docs/_api-mocking/mock.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -14,13 +14,15 @@ description: |
{: .warning}
parameters:
- name: matcher
versionAdded: 2.0.0
types:
- String
- Regex
- Function
- Object
content: Criteria for which calls to `fetch` should match this route
- name: response
versionAdded: 2.0.0
types:
- String
- Object
Expand All @@ -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
Expand Down
19 changes: 18 additions & 1 deletion docs/_api-mocking/mock_matcher.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: 'matcher'
position: 1.1
versionAdded: 1.0.0
description: |-
Criteria for deciding which requests to mock.
Expand All @@ -18,6 +19,7 @@ parentMethod: mock
parentMethodGroup: mocking
parameters:
- name: '*'
versionAdded: 5.0.0
types:
- String
content: Match any url
Expand All @@ -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:
Expand All @@ -44,6 +46,7 @@ parameters:
content: Match a url beginning with a string
- name: |-
end:...
versionAdded: 5.7.0
types:
- String
examples:
Expand All @@ -61,6 +64,7 @@ parameters:
content: Match a url which has a given path
- name: |-
glob:...
versionAdded: 5.7.0
types:
- String
examples:
Expand All @@ -69,6 +73,7 @@ parameters:
content: Match a url using a glob pattern
- name: |-
express:...
versionAdded: 5.7.0
types:
- String
examples:
Expand All @@ -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
Expand All @@ -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'}}
Expand All @@ -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
Expand All @@ -116,13 +126,15 @@ parameters:
content: |-
Use a function matcher, as described above
- name: method
versionAdded: 2.1.0
types:
- String
content: |-
Match only requests using this http method. Not case-sensitive
examples:
- get, POST
- name: headers
versionAdded: 1.0.0
types:
- Object
- Headers
Expand Down Expand Up @@ -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: |-
Expand All @@ -158,6 +171,7 @@ parameters:
- |-
{"q": "cute+kittenz", "format": "gif"}
- name: params
versionAdded: 6.0.0
types:
- Object
content: |-
Expand All @@ -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/`
Expand Down
1 change: 1 addition & 0 deletions docs/_api-mocking/mock_once.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions docs/_api-mocking/mock_options.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: 'options'
position: 1.3
versionAdded: 5.0.0
description: |-
An object containing further options for configuring mocking behaviour.
Expand All @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions docs/_api-mocking/mock_response.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ parentMethodGroup: mocking
parameters:
- types:
- Response
versionAdded: 5.0.0
examples:
- "new Response('ok', {status: 200})"
content: |
Expand All @@ -24,23 +25,27 @@ 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:
- 200, 404, 503
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
Expand All @@ -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
Expand All @@ -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: |-
Expand All @@ -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:
Expand Down
Loading

0 comments on commit b2cf53c

Please sign in to comment.