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

ResponseConfigurator

Direct Subclass:

Fixture, Preset

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.

Test:

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

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 Methods
private abstract

Public Constructors

public constructor(server: Server) version 1.0.0 since 2.0.0 source

Response configurator constructor

Params:

NameTypeAttributeDescription
server Server
  • optional
  • default: null

Server instance

Public Members

public get and: ResponseConfigurator: * version 1.0.0 since 2.0.0 source

Sugar for chaining

Return:

ResponseConfigurator

this

public server: Server | null since 2.0.0 source

Stores the server instance

public get with: ResponseConfigurator: * version 1.0.0 since 2.0.0 source

Sugar for chaining

Return:

ResponseConfigurator

this

Private Members

private _any: Object since 2.0.0 source

Default response for fixture or preset. For fixture, it will be used when ordered responses are not matching defined call counts.

private _responseKeys: Array since 2.0.0 source

Allowed response keys

Public Methods

public after(cb: Function): ResponseConfigurator version 1.0.0 since 2.0.0 source

Set the after callback

Params:

NameTypeAttributeDescription
cb Function

Callback

Return:

ResponseConfigurator

this

public before(cb: Function): ResponseConfigurator version 1.0.0 since 2.0.0 source

Set the before callback

Params:

NameTypeAttributeDescription
cb Function

Callback

Return:

ResponseConfigurator

this

public body(body: String | Function): ResponseConfigurator version 1.0.0 since 2.0.0 source

Set the response body

Params:

NameTypeAttributeDescription
body String | Function

[description]

Return:

ResponseConfigurator

this

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

Params:

NameTypeAttributeDescription
delay Boolean | Number

Delay in ms or false to remove delay

Return:

ResponseConfigurator

this

See:

public header(name: String, content: String, append: Boolean): ResponseConfigurator version 1.0.0 since 2.2.0 source

Set a specific header value

Params:

NameTypeAttributeDescription
name String

Header name

content String

Header content

append Boolean
  • optional
  • default: false

If true, the content will be appended to header, otherwise it replaces current value

Return:

ResponseConfigurator

this

Test:

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

Params:

NameTypeAttributeDescription
headers Object | Headers | Boolean
  • optional
  • default: {}

Headers. Passing false will remove all headers and passing nothing will reset all headers

Return:

ResponseConfigurator

this

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:

NameTypeAttributeDescription
pattern String

Pattern

Return:

ResponseConfigurator

this

Test:

See:

public set(params: Object): * version 1.0.0 since 2.0.0 source

Set the response parameters based on the object provided

Params:

NameTypeAttributeDescription
params Object
  • optional
  • default: {}

Parameters

Return:

*

Test:

See:

public status(status: Number): ResponseConfigurator version 1.0.0 since 2.0.0 source

Set the response status

Params:

NameTypeAttributeDescription
status Number

Status code

Return:

ResponseConfigurator

this

public statusText(text: String): ResponseConfigurator version 1.0.0 since 2.0.0 source

Set the response status text

Params:

NameTypeAttributeDescription
text String

Status text

Return:

ResponseConfigurator

this

public wrapper(wrapper: Function | Boolean): ResponseConfigurator version 1.0.0 since 2.0.0 source

Set the response body wrapper

Params:

NameTypeAttributeDescription
wrapper Function | Boolean

Response body wrapper

Return:

ResponseConfigurator

this

Private Methods

private abstract _getCurrentResponseSet() source