Manual Reference Source Test
import {Preset} from 'fetch-mock-fixtures/src/Preset.js'
public class | source

Preset

Extends:

ResponseConfigurator → Preset

Presets are a quick way to add common response configuration and avoid duplicating it through all fixtures when configuring server response.

Configuration itself is, like the fixtures, based on ResponseConfigurator methods.

Constructor Summary

Public Constructor
public

constructor(server: Server, name: String, preset: Object)

Create a new preset instance that can be configured in the same manner than a regular fixture

version 1.0.0 since 2.0.0

Member Summary

Public Members
public

name: *

Method Summary

Public Methods
public

Register/update the preset in the global pool.

version 1.0.0 since 2.2.0
public

Remove the preset from the server's instance pool

If the preset is also globally registered, it won't be removed from the global pool

version 1.0.0 since 2.2.0
public

Unregister the preset from the global pool.

version 1.0.0 since 2.2.0
Private Methods
private

Presets can only handle a default response

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, name: String, preset: Object) version 1.0.0 since 2.0.0 source

Create a new preset instance that can be configured in the same manner than a regular fixture

Override:

ResponseConfigurator#constructor

Params:

NameTypeAttributeDescription
server Server

Server instance

name String

Preset name

preset Object
  • optional

Preset configuration object

Public Members

public name: * source

Public Methods

public register(): Preset version 1.0.0 since 2.2.0 source

Register/update the preset in the global pool. This made the preset available into all server's instances created from the registration

Return:

Preset

Self for chaining

public remove(): Preset version 1.0.0 since 2.2.0 source

Remove the preset from the server's instance pool

If the preset is also globally registered, it won't be removed from the global pool

Return:

Preset

self for chaining

public unregister(): Preset version 1.0.0 since 2.2.0 source

Unregister the preset from the global pool.

Return:

Preset

Self for chaining

Private Methods

private _getCurrentResponseSet(): Object version 1.0.0 since 2.0.0 source

Presets can only handle a default response

Override:

ResponseConfigurator#_getCurrentResponseSet

Return:

Object

Current response configuration