Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

Index

Properties

autoRespond

autoRespond: boolean

When set to true, causes the server to automatically respond to incoming requests after a timeout. The default timeout is 10ms but you can control it through the autoRespondAfter property. Note that this feature is intended to help during mockup development, and is not suitable for use in tests.

autoRespondAfter

autoRespondAfter: number

When autoRespond is true, respond to requests after this number of milliseconds. Default is 10.

fakeHTTPMethods

fakeHTTPMethods: boolean

If set to true, server will find _method parameter in POST body and recognize that as the actual method. Supports a pattern common to Ruby on Rails applications. For custom HTTP method faking, override server.getHTTPMethod(request).

requests

You can inspect the server.requests to verify request ordering, find unmatched requests or check that no requests has been done. server.requests is an array of all the FakeXMLHttpRequest objects that have been created.

respondImmediately

respondImmediately: boolean

If set, the server will respond to every request immediately and synchronously. This is ideal for faking the server from within a test without having to call server.respond() after each request made in that test. As this is synchronous and immediate, this is not suitable for simulating actual network latency in tests or mockups. To simulate network latency with automatic responses, see server.autoRespond and server.autoRespondAfter.

Methods

getHTTPMethod

  • Used internally to determine the HTTP method used with the provided request. By default this method simply returns request.method. When server.fakeHTTPMethods is true, the method will return the value of the _method parameter if the method is “POST”. This method can be overridden to provide custom behavior.

    Parameters

    Returns string

respond

  • respond(): void
  • Causes all queued asynchronous requests to receive a response. If none of the responses added through respondWith match, the default response is [404, {}, ""]. Synchronous requests are responded to immediately, so make sure to call respondWith upfront. If called with arguments, respondWith will be called with those arguments before responding to requests.

    Returns void

respondWith

  • respondWith(body: string): void
  • respondWith(response: any[]): void
  • respondWith(fn: (xhr: SinonFakeXMLHttpRequest) => void): void
  • respondWith(url: string, body: string): void
  • respondWith(url: string, response: any[]): void
  • respondWith(url: string, fn: (xhr: SinonFakeXMLHttpRequest) => void): void
  • respondWith(method: string, url: string, body: string): void
  • respondWith(method: string, url: string, response: any[]): void
  • respondWith(method: string, url: string, fn: (xhr: SinonFakeXMLHttpRequest) => void): void
  • respondWith(url: RegExp, body: string): void
  • respondWith(url: RegExp, response: any[]): void
  • respondWith(url: RegExp, fn: (xhr: SinonFakeXMLHttpRequest) => void): void
  • respondWith(method: string, url: RegExp, body: string): void
  • respondWith(method: string, url: RegExp, response: any[]): void
  • respondWith(method: string, url: RegExp, fn: (xhr: SinonFakeXMLHttpRequest) => void): void
  • Causes the server to respond to any request not matched by another response with the provided data. The default catch-all response is [404, {}, ""]. A String representing the response body An Array with status, headers and response body, e.g. [200, { "Content-Type": "text/html", "Content-Length": 2 }, "OK"] A Function. Default status is 200 and default headers are none. When the response is a Function, it will be passed the request object. You must manually call respond on it to complete the request.

    Parameters

    • body: string

      A String representing the response body

    Returns void

  • Causes the server to respond to any request not matched by another response with the provided data. The default catch-all response is [404, {}, ""]. Default status is 200 and default headers are none. When the response is a Function, it will be passed the request object. You must manually call respond on it to complete the request.

    Parameters

    • response: any[]

      An Array with status, headers and response body, e.g. [200, { "Content-Type": "text/html", "Content-Length": 2 }, "OK"]

    Returns void

  • Causes the server to respond to any request not matched by another response with the provided data. The default catch-all response is [404, {}, ""]. Default status is 200 and default headers are none. When the response is a Function, it will be passed the request object. You must manually call respond on it to complete the request.

    Parameters

    Returns void

  • Responds to all requests to given URL, e.g. /posts/1.

    Parameters

    • url: string
    • body: string

    Returns void

  • Responds to all requests to given URL, e.g. /posts/1.

    Parameters

    • url: string
    • response: any[]

    Returns void

  • Responds to all requests to given URL, e.g. /posts/1.

    Parameters

    Returns void

  • Responds to all method requests to the given URL with the given response. method is an HTTP verb.

    Parameters

    • method: string
    • url: string
    • body: string

    Returns void

  • Responds to all method requests to the given URL with the given response. method is an HTTP verb.

    Parameters

    • method: string
    • url: string
    • response: any[]

    Returns void

  • Responds to all method requests to the given URL with the given response. method is an HTTP verb.

    Parameters

    Returns void

  • URL may be a regular expression, e.g. /\/post\//\d+ If the response is a Function, it will be passed any capture groups from the regular expression along with the XMLHttpRequest object:

    Parameters

    Returns void

  • URL may be a regular expression, e.g. /\/post\//\d+ If the response is a Function, it will be passed any capture groups from the regular expression along with the XMLHttpRequest object:

    Parameters

    Returns void

  • URL may be a regular expression, e.g. /\/post\//\d+ If the response is a Function, it will be passed any capture groups from the regular expression along with the XMLHttpRequest object:

    Parameters

    Returns void

  • Responds to all method requests to URLs matching the regular expression.

    Parameters

    • method: string
    • url: RegExp
    • body: string

    Returns void

  • Responds to all method requests to URLs matching the regular expression.

    Parameters

    • method: string
    • url: RegExp
    • response: any[]

    Returns void

  • Responds to all method requests to URLs matching the regular expression.

    Parameters

    Returns void

restore

  • restore(): void
  • Returns void