Test utilities.
- Source:
Methods
(static) expectDeleted(record, optionsopt) → {Promise}
- Source:
Ensures that a database record has been deleted by attempting to reload a fresh instance.
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
record |
object | A database record (an instance of a Bookshelf model). |
|||||||||||
options |
options |
<optional> |
Options. Properties
|
Returns:
A promise that is resolved if no record with the same ID is found in the database, or rejected if one is found.
- Type
- Promise
(static) expectErrors(res, expectedErrorOrErrors)
- Source:
Ensures that a response from the server is a correctly formatted error response and that it contains the expected error or list of errors.
// Expect a single error.
expectErrors(res, {
code: 'something.wrong',
message: 'It went wrong...'
});
// Expect a list of errors.
expectErrors(res, [
{
code: 'something.wrong',
message: 'It went wrong...'
},
{
code: 'something.bad',
message: 'What?'
}
]);
An error response is expected to:
- Have the application/json content type
- Be a JSON object with a single
errors
property that is an array of errors
Parameters:
Name | Type | Description |
---|---|---|
res |
Response | A response object from a test. |
expectedErrorOrErrors |
object | Array.<object> | A single error or a list of errors that is expected to
be in the response. The response is expected to contain exactly this or these
errors and no others. If a single error is given, the response's |
(static) expectUnchanged(record, optionsopt) → {Promise}
- Source:
Ensures that a database record has not changed by reloading a fresh instance and comparing its attributes.
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
record |
object | A database record (an instance of a Bookshelf model). |
|||||||||||
options |
object |
<optional> |
Options. Properties
|
Returns:
A promise that is resolved if the record has not changed, or rejected if it has changed.
- Type
- Promise