Manual Reference Source Test
import {Fixture} from 'fetch-mock-fixtures/src/Fixture.js'
public class | version 1.0.0 | since 2.0.0 | source

Fixture

Extends:

ResponseConfigurator → Fixture

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

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

to: Fixture: *

Syntax sugar for human readability

version 1.0.0 since 1.0.0
public get

Alias for on

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

firstCall(own: boolean): *

public

getPath(request: *, response: *): *

public

getResponse(request: *): *

public

async match(request: *, server: *): *

public

preset(name: *): *

public

secondCall(own: boolean): *

public

async sleep(delay: *)

public

thirdCall(own: boolean): *

public

throw(message: string)

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

Set the response body

version 1.0.0 since 2.0.0
public

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

Set the pattern that will be used to match the request

version 1.0.0 since 2.0.0
public

set(params: Object): *

Set the response parameters based on the object provided

version 1.0.0 since 2.0.0
public

Set the response status

version 1.0.0 since 2.0.0
public

Set the response status text

version 1.0.0 since 2.0.0
public

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#constructor

Params:

NameTypeAttributeDescription
server Server
  • optional

Server instance

Public Members

public get any: * source

public calls: Number since 2.0.0 source

Stores the number of responses generated by this fixture

public get fallback: Fixture: * version 1.0.0 since 2.0.0 source

Alias for respond that always return the fallback fixture

Return:

Fixture

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

Return:

RequestMatcher

Request matcher

public ownCalls: Array since 2.0.0 source

Stores the response which are specific to own call count

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

Return:

Fixture

Fixture

public get to: Fixture: * version 1.0.0 since 1.0.0 source

Syntax sugar for human readability

Return:

Fixture

public get when: RequestMatcher: * version 1.0.0 since 2.0.0 source

Alias for on

Return:

RequestMatcher

Request matcher

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#_any

private _callnum: null | Number since 2.0.0 source

Flag for response configuration

private _matcher: null | RequestMatcher since 2.0.0 source

Request matcher instance

private _ownCall: Boolean since 2.0.0 source

Flag for call count configuration

private _responseKeys: Array since 2.0.0 source

Allow response key for configuration

Override:

ResponseConfigurator#_responseKeys

Public Methods

public call(n: *, own: *): * source

Params:

NameTypeAttributeDescription
n *
own *

Return:

*

public extractParams(pathname: *, pattern: *): * source

Params:

NameTypeAttributeDescription
pathname *
pattern *

Return:

*

public firstCall(own: boolean): * source

Params:

NameTypeAttributeDescription
own boolean
  • optional
  • default: false

Return:

*

public getPath(request: *, response: *): * source

Params:

NameTypeAttributeDescription
request *
response *

Return:

*

public getResponse(request: *): * source

Params:

NameTypeAttributeDescription
request *

Return:

*

public async match(request: *, server: *): * source

Params:

NameTypeAttributeDescription
request *
server *

Return:

*

public preset(name: *): * source

Params:

NameTypeAttributeDescription
name *

Return:

*

public secondCall(own: boolean): * source

Params:

NameTypeAttributeDescription
own boolean
  • optional
  • default: false

Return:

*

public async sleep(delay: *) source

Params:

NameTypeAttributeDescription
delay *

public thirdCall(own: boolean): * source

Params:

NameTypeAttributeDescription
own boolean
  • optional
  • default: false

Return:

*

public throw(message: string) source

Params:

NameTypeAttributeDescription
message string
  • optional
  • default:

public wrap(body: *, wrapper: *): * source

Params:

NameTypeAttributeDescription
body *
wrapper *

Return:

*

Private Methods

private async _buildResponse(request: *, response: *): * source

Params:

NameTypeAttributeDescription
request *
response *

Return:

*

private _exceptionManagement(err: *, message: *): * source

Params:

NameTypeAttributeDescription
err *
message *

Return:

*

private _getCurrentResponseSet(): Object version 1.0.0 since 2.0.0 source

Target the current response set based on call count configuration

Override:

ResponseConfigurator#_getCurrentResponseSet

Return:

Object

Response configuration object