SuperRest

SuperRest

SuperTest helpers to test REST APIs.

Constructor

new SuperRest(app, optionsopt)

Source:
See:

Returns a SuperREST instance to test the specified application.

Parameters:
Name Type Attributes Description
app Application

The application to test.

options object <optional>

SuperREST configuration that applies to your entire API.

Properties
Name Type Attributes Default Description
expectedContentType string | RegExp <optional>

The default Content-Type header that the server is expected to use in responses. An exact match is required if it's a string.

pathPrefix string <optional>

A prefix common to all your API routes. If given at construction, you won't have to repeat it for each test.

updateMethod string <optional>
"PUT"

The HTTP method used when calling the update method. You might want to use PATCH if your API uses only that, or use the patch method instead.

Methods

create(path, body, optionsopt)

Source:

Makes a POST request to create a resource with the specified body. The response is expected to have the status code HTTP 201 Created by default.

Parameters:
Name Type Attributes Description
path string

The path of the API resource. If a non-false pathPrefix option is given to the constructor or to this method, it will be prepended to the path to form the full test path.

body *

The request body to send to the server.

options object <optional>

Assertion options (see SuperRest#test for all options).

Properties
Name Type Attributes Default Description
expectedStatusCode number <optional>
201

The expected HTTP status code of the response.

delete(path, bodyopt, optionsopt)

Source:

Makes a DELETE request to delete a resource.

Parameters:
Name Type Attributes Description
path string

The path of the API resource. If a non-false pathPrefix option is given to the constructor or to this method, it will be prepended to the path to form the full test path.

body * <optional>

An optional request body to send to the server.

options object <optional>

Assertion options (see SuperRest#test for all options).

destroy(path, bodyopt, optionsopt)

Source:

Makes a DELETE request to destroy a resource.

Parameters:
Name Type Attributes Description
path string

The path of the API resource. If a non-false pathPrefix option is given to the constructor or to this method, it will be prepended to the path to form the full test path.

body * <optional>

An optional request body to send to the server.

options object <optional>

Assertion options (see SuperRest#test for all options).

expect(res, optionsopt)

Source:

Make default RESTful assertions on a SuperTest response.

This method is used by SuperRest#test (and all CRUD aliases). You may override it to perform additional assertions.

Parameters:
Name Type Attributes Description
res Response

A SuperTest response.

options object <optional>

Assertion options.

Properties
Name Type Attributes Default Description
expectedContentType string | RegExp <optional>

The Content-Type header expected to be found in the response. An exact match is required if it's a string. Overrides the expectedContentType option given to the constructor.

expectedStatusCode number <optional>
200

The expected HTTP status code of the response.

patch(path, body, optionsopt)

Source:

Makes a PATCH request to partially update a resource with the specified body.

Parameters:
Name Type Attributes Description
path string

The path of the API resource. If a non-false pathPrefix option is given to the constructor or to this method, it will be prepended to the path to form the full test path.

body *

The request body to send to the server.

options object <optional>

Assertion options (see SuperRest#test for all options).

read(path, optionsopt)

Source:

Makes a GET request to read a resource.

Parameters:
Name Type Attributes Description
path string

The path of the API resource. If a non-false pathPrefix option is given to the constructor or to this method, it will be prepended to the path to form the full test path.

options object <optional>

Assertion options (see SuperRest#test for all options).

retrieve(path, optionsopt)

Source:

Makes a GET request to retrieve a resource.

Parameters:
Name Type Attributes Description
path string

The path of the API resource. If a non-false pathPrefix option is given to the constructor or to this method, it will be prepended to the path to form the full test path.

options object <optional>

Assertion options (see SuperRest#test for all options).

test(methodopt, path, bodyopt, optionsopt)

Source:

Starts and returns a SuperTest chain.

Parameters:
Name Type Attributes Default Description
method string <optional>
"GET"

The HTTP method.

path string

The path of the API resource to test. If a non-false pathPrefix option is given to the constructor or to this method, it will be prepended to the path to form the full test path.

body * <optional>

The request body to send to the server, if any.

options object <optional>

Test options.

Properties
Name Type Attributes Default Description
expectedContentType string | RegExp <optional>

The Content-Type header expected to be found in the response. An exact match is required if it's a string. Overrides the expectedContentType option given to the constructor.

expectedStatusCode number <optional>
200

The expected HTTP status code of the response.

pathPrefix boolean | string <optional>

A path prefix to use for this specific test. Overrides the pathPrefix option given to the constructor. If false and a pathPrefix option was given to the constructor, it is not used (the path argument is used as is).

update(path, body, optionsopt)

Source:

Makes a PUT request to update a resource with the specified body.

Parameters:
Name Type Attributes Description
path string

The path of the API resource. If a non-false pathPrefix option is given to the constructor or to this method, it will be prepended to the path to form the full test path.

body *

The request body to send to the server.

options object <optional>

Assertion options (see SuperRest#test for all options).