import {ResponseConfigurator} from 'fetch-mock-fixtures/src/helpers/ResponseConfigurator.js'
ResponseConfigurator
The response configurator class is common to fixtures and presets and offers a set of tools to configure response content and behavior.
This class should be seen as an abstract class as it uses _getCurrentResponseSet
of its
child to locate the response to configure
Note : The response configurator does not contain logic to follow calls count.
Constructor Summary
Public Constructor | ||
public |
constructor(server: Server) Response configurator constructor |
version 1.0.0 since 2.0.0 |
Member Summary
Public Members | ||
public get |
Sugar for chaining |
version 1.0.0 since 2.0.0 |
public |
Stores the server instance |
since 2.0.0 |
public get |
Sugar for chaining |
version 1.0.0 since 2.0.0 |
Private Members | ||
private |
Default response for fixture or preset. |
since 2.0.0 |
private |
Allowed response keys |
since 2.0.0 |
Method Summary
Public Methods | ||
public |
Set the after callback |
version 1.0.0 since 2.0.0 |
public |
Set the before callback |
version 1.0.0 since 2.0.0 |
public |
body(body: String | Function): ResponseConfigurator Set the response body |
version 1.0.0 since 2.0.0 |
public |
delay(delay: Boolean | Number): ResponseConfigurator Set the time the server will wait before sending back response |
version 1.0.0 since 2.0.0 |
public |
header(name: String, content: String, append: Boolean): ResponseConfigurator Set a specific header value |
version 1.0.0 since 2.2.0 |
public |
headers(headers: Object | Headers | Boolean): ResponseConfigurator One time setter for all headers |
version 1.0.1 since 2.0.0 |
public |
pattern(pattern: String): ResponseConfigurator Set the pattern that will be used to match the request |
version 1.0.0 since 2.0.0 |
public |
Set the response parameters based on the object provided |
version 1.0.0 since 2.0.0 |
public |
status(status: Number): ResponseConfigurator Set the response status |
version 1.0.0 since 2.0.0 |
public |
statusText(text: String): ResponseConfigurator Set the response status text |
version 1.0.0 since 2.0.0 |
public |
wrapper(wrapper: Function | Boolean): ResponseConfigurator Set the response body wrapper |
version 1.0.0 since 2.0.0 |
Private Methods | ||
private abstract |
|
Public Constructors
Public Members
Private Members
Public Methods
public after(cb: Function): ResponseConfigurator version 1.0.0 since 2.0.0 source
Set the after callback
Params:
Name | Type | Attribute | Description |
cb | Function | Callback |
public before(cb: Function): ResponseConfigurator version 1.0.0 since 2.0.0 source
Set the before callback
Params:
Name | Type | Attribute | Description |
cb | Function | Callback |
public body(body: String | Function): ResponseConfigurator version 1.0.0 since 2.0.0 source
Set the response body
public delay(delay: Boolean | Number): ResponseConfigurator version 1.0.0 since 2.0.0 source
Set the time the server will wait before sending back response
See:
public header(name: String, content: String, append: Boolean): ResponseConfigurator version 1.0.0 since 2.2.0 source
Set a specific header value
public headers(headers: Object | Headers | Boolean): ResponseConfigurator version 1.0.1 since 2.0.0 source
One time setter for all headers
It can accept object or an header instance
public pattern(pattern: String): ResponseConfigurator version 1.0.0 since 2.0.0 source
Set the pattern that will be used to match the request
Params:
Name | Type | Attribute | Description |
pattern | String | Pattern |
public set(params: Object): * version 1.0.0 since 2.0.0 source
Set the response parameters based on the object provided
Params:
Name | Type | Attribute | Description |
params | Object |
|
Parameters |
Return:
* |
See:
- ResponseConfigurator#_responseKeys for available keys
public status(status: Number): ResponseConfigurator version 1.0.0 since 2.0.0 source
Set the response status
Params:
Name | Type | Attribute | Description |
status | Number | Status code |
public statusText(text: String): ResponseConfigurator version 1.0.0 since 2.0.0 source
Set the response status text
Params:
Name | Type | Attribute | Description |
text | String | Status text |
public wrapper(wrapper: Function | Boolean): ResponseConfigurator version 1.0.0 since 2.0.0 source
Set the response body wrapper