Skip to content

Commit

Permalink
clearer docs on shorthand mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
wheresrhys committed Oct 21, 2015
1 parent b5dd496 commit 2ebd5c4
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@ Requests can be mocked based on a wide range of criteria (method, headers, url),
`require('fetch-mock')` exports a singleton with the following methods

### `mock(config)`
Replaces `fetch()` with a stub which records it's calls, grouped by route, and optionally returns a stub response or passes the call through to `fetch()`. `config` is an optional* object with the following properties.
Replaces `fetch()` with a stub which records it's calls, grouped by route, and optionally returns a stub response or passes the call through to `fetch()`.

#### *Shorthand notation for simplest use cases*
The following are also accepted by mock()
`config` is an optional (when persistent routes are already defined using `registerRoute`) object with properties as below:

> ##### *Shorthand notation for simplest use cases*
The following are also accepted by mock() and translated into `config` objects with the `routes` property defined using the values passed in to mock as follows:
* `mock(name, matcher, response)` - configuration for a single named route to be mocked
* `mock(matcher, response)` - configuration for a single unnamed route to be mocked. To access details of its calls `fetchMock.calls()` should be called without passing a parameter
* `mock(response)` - configuration object for a single route
* `mock(responses` - array of route configuration objects
* `mock(route)` - configuration object for a single route
* `mock(routes)` - array of route configuration objects



* `routes`: Either a single object or an array of similar objects each defining how the mock handles a given request. If multiple routes are specified the first matching route will be used to define the response. Each route object must have the following properties.
* `name`: A unique string naming the route
Expand Down Expand Up @@ -78,9 +82,6 @@ The following are also accepted by mock()
* 'good': all unmatched calls result in a resolved promise with a 200 status


\* `config` is optional only when preconfigured routes have already been setup


### `restore()`
Restores `fetch()` to its unstubbed state and clears all data recorded for its calls

Expand Down

0 comments on commit 2ebd5c4

Please sign in to comment.