import {Fixture} from 'fetch-mock-fixtures/src/Fixture.js'
Fixture
Extends:
A fixture contains all the needed informations to find out wich request can be matched and wich response must be sent back
Constructor Summary
Public Constructor | ||
public |
constructor(server: Server) Initialize the ResponseConfigurator helper |
version 1.0.0 since 2.0.0 |
Member Summary
Public Members | ||
public get |
any: * |
|
public |
Stores the number of responses generated by this fixture |
since 2.0.0 |
public get |
Alias for respond that always return the fallback fixture |
version 1.0.0 since 2.0.0 |
public |
Stores the response which are specific to global call count |
since 2.0.0 |
public get |
on: RequestMatcher: * Set the fixture in request matching mode. |
version 1.0.0 since 2.0.0 |
public |
Stores the response which are specific to own call count |
since 2.0.0 |
public get |
Ask server to process the respond. |
version 1.0.0 since 2.0.0 |
public get |
Syntax sugar for human readability |
version 1.0.0 since 1.0.0 |
public get |
when: RequestMatcher: * Alias for |
version 1.0.0 since 2.0.0 |
Private Members | ||
private |
_any: * |
|
private |
Flag for response configuration |
since 2.0.0 |
private |
Request matcher instance |
since 2.0.0 |
private |
Flag for call count configuration |
since 2.0.0 |
private |
Allow response key for configuration |
since 2.0.0 |
Method Summary
Public Methods | ||
public |
call(n: *, own: *): * |
|
public |
extractParams(pathname: *, pattern: *): * |
|
public |
|
|
public |
getPath(request: *, response: *): * |
|
public |
getResponse(request: *): * |
|
public |
async match(request: *, server: *): * |
|
public |
preset(name: *): * |
|
public |
secondCall(own: boolean): * |
|
public |
async sleep(delay: *) |
|
public |
|
|
public |
|
|
public |
wrap(body: *, wrapper: *): * |
Private Methods | ||
private |
async _buildResponse(request: *, response: *): * |
|
private |
_exceptionManagement(err: *, message: *): * |
|
private |
Target the current response set based on call count configuration |
version 1.0.0 since 2.0.0 |
Inherited Summary
From class ResponseConfigurator | ||
public get |
Sugar for chaining |
version 1.0.0 since 2.0.0 |
public get |
Sugar for chaining |
version 1.0.0 since 2.0.0 |
public |
Stores the server instance |
since 2.0.0 |
private |
Default response for fixture or preset. |
since 2.0.0 |
private |
Allowed response keys |
since 2.0.0 |
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 abstract |
|
Public Constructors
public constructor(server: Server) version 1.0.0 since 2.0.0 source
Initialize the ResponseConfigurator helper
Override:
ResponseConfigurator#constructorParams:
Name | Type | Attribute | Description |
server | Server |
|
Server instance |
Public Members
public get any: * source
public get fallback: Fixture: * version 1.0.0 since 2.0.0 source
Alias for respond that always return the fallback fixture
public globalCalls: Array since 2.0.0 source
Stores the response which are specific to global call count
public get on: RequestMatcher: * version 1.0.0 since 2.0.0 source
Set the fixture in request matching mode. The matcher is behing a proxy to allow quick property mapping
public get respond: Fixture: * version 1.0.0 since 2.0.0 source
Ask server to process the respond. If the fixture is already in response mode, a new fixture will be returned. Otherwise, it will be the same fixture
Private Members
private _any: * source
Default response for fixture or preset. For fixture, it will be used when ordered responses are not matching defined call counts.
Override:
ResponseConfigurator#_anyprivate _responseKeys: Array since 2.0.0 source
Allow response key for configuration
Override:
ResponseConfigurator#_responseKeysPublic Methods
public extractParams(pathname: *, pattern: *): * source
Params:
Name | Type | Attribute | Description |
pathname | * | ||
pattern | * |
Return:
* |
public firstCall(own: boolean): * source
Params:
Name | Type | Attribute | Description |
own | boolean |
|
Return:
* |
public getPath(request: *, response: *): * source
Params:
Name | Type | Attribute | Description |
request | * | ||
response | * |
Return:
* |
public async match(request: *, server: *): * source
Params:
Name | Type | Attribute | Description |
request | * | ||
server | * |
Return:
* |
public secondCall(own: boolean): * source
Params:
Name | Type | Attribute | Description |
own | boolean |
|
Return:
* |
public async sleep(delay: *) source
Params:
Name | Type | Attribute | Description |
delay | * |
public thirdCall(own: boolean): * source
Params:
Name | Type | Attribute | Description |
own | boolean |
|
Return:
* |
public throw(message: string) source
Params:
Name | Type | Attribute | Description |
message | string |
|
public wrap(body: *, wrapper: *): * source
Params:
Name | Type | Attribute | Description |
body | * | ||
wrapper | * |
Return:
* |
Private Methods
private async _buildResponse(request: *, response: *): * source
Params:
Name | Type | Attribute | Description |
request | * | ||
response | * |
Return:
* |
private _exceptionManagement(err: *, message: *): * source
Params:
Name | Type | Attribute | Description |
err | * | ||
message | * |
Return:
* |