3.2.1 • Published 3 years ago
restspec v3.2.1
restspec rest-api test
usage
- npm install restspec --save-dev
var Restspec = require('restspec');
new Restspec(options);
options
name
String, This test's name.urlRoot
String, Url root eg. http://127.0.0.1cases
Array, Test cases.hooks
Object, Hooks function.done
Function, Called when test cases exec done.
globals.request.headers
Object,
case
name
String, This is name of caseuri
String, Request url isurlRoot
concaturi
. eg. /sessionverb
String, Enumget
,post
,put
,patch
,delete
defaultget
headers
Object, Request customer headers.data
Fixed, Request send data.expects
Status
response.statusCodeJSON
assert response.body
//case1. assert body
JSON: {
id: 1,
name: 'Hello'
}
//case2. body is an array, assert one
JSON: ['0', {
id: 1,
name: 'Hello'
}]
//case2. body is an array, assert all
JSON: ['*', {
id: 1,
name: 'Hello'
}]
JSONTypes
assert response.body typeJSONLength
assert response.body lengthHeader
assert one response.headers
Header: ['x-content-record-total', '2']
Headers
assert some response.headers
Headers: [
['x-content-record-total', '2'],
['content-type', 'application/json']
]
Advanced Usage
JSON: {
// assert is require('assert')
id: function(actual, assert) {
assert.equal(typeof actual, 'number');
assert.equal(actual, 20);
}
var case = {
name: 'This is name of case',
uri: '/session',
expects: {
Status: 201,
JSON: {
id: 1,
name: 'Hello world'
},
JSONTypes: ['parent', {
id: Number,
name: String
}]
}
}
var case = function(lastBody, lastRes) {
return {
name: 'This is function return case'
uri: '/session',
expects: {
Status: 201,
JSON: {
id: 1,
name: 'Hello world'
},
JSONTypes: ['parent', {
id: Number,
name: String
}]
}
}
};
var case = function(lastBody, lastRes) {
return new Promise(function(resolve, reject) {
return resolve({
name: 'This is function return case with promise'
uri: '/session',
expects: {
Status: 201,
JSON: {
id: 1,
name: 'Hello world'
},
JSONTypes: ['parent', {
id: Number,
name: String
}]
}
})
};
};
var case = async () => {
const user = await Model.findOne({ where: { id: 1 } });
// If the function is returned, it will be called.
return () => {
const { age } = user;
if (age <= 18) return new Error(`Adult only: ${age}`);
return null;
};
};
};
var case = () => {
const age = 17;
// Error instances can be returned directly.
if (age <= 18) return new Error(`Adult only: ${age}`);
return null;
};
Comment
- cases run one by one
3.2.1
3 years ago
3.2.0
5 years ago
3.1.1
5 years ago
3.1.0
5 years ago
3.0.1
7 years ago
3.0.0
8 years ago
2.2.0
8 years ago
2.1.0
8 years ago
2.0.0
8 years ago
1.1.0
8 years ago
1.0.2
8 years ago
1.0.1
8 years ago
1.0.0
8 years ago
0.7.5
9 years ago
0.7.4
9 years ago
0.7.3
9 years ago
0.7.2
9 years ago
0.7.1
10 years ago
0.7.0
10 years ago
0.6.2
10 years ago
0.6.1
10 years ago
0.6.0
10 years ago
0.5.0
10 years ago
0.1.0
10 years ago