Simulado


2.x docs
Install
npm i simulado --save-dev
or
docker run -p <desired_port>:80 ldabiralai/simulado
Usage
CLI
This will keep the server alive until the process is killed (unlike the below).
./node_modules/.bin/simulado
Options
-p, --port - Port number that Simulado should start on.
-f, --file - Path to a JSON file containing mocks to mock on startup.
For HTTPS, use the following options
-c, --cert <filepath> - Path to certificate
-k, --key <filepath> - Path to certificate key
Web Client
Once Simulado has started, going to http://localhost:<SIMULADO_PORT_NUM> will display a list of mocked endpoints and their responses.
Basic Usage (ES6)
import simulado from 'simulado';
import axios from 'axios';
(async function() {
await simulado.start();
await simulado.setMock({
path: '/data',
body: 'Hello World!'
});
const response = await axios.get('http://localhost:7001/data');
console.log(response.data);
await simulado.stop();
})();
API
start([options])
Start Simulado
- options
<Object>
port <number> - Specify the port number to start Simulado on. Default: 7001
https <object> - Enable https support
key <string> - path to key file
cert <string> - path to cert file
setRemoteServer(url)
Sets the url of a simulado instance on which the client should set mocks, for use if simulado lives on another server.
url <String> for example https://my-simulado-server.herokuapp.com
isRunning()
Returns true if simulado is running. Returns false if simulado is not started.
setMock(mockResponse)
Sets a mock response
setMocks(mockResponses)
Sets multiple mock responses
setDefaults(mockResponses)
Clears mocked responses and sets new mocked responses
lastRequests(method, path[, limit])
Fetch the last requests for a path
method <String> - The request method for the requests you want to fetch
path <String> - The path of the requests you want to fetch
limit <number> - Only return the given number of last requests
lastRequest(method, path)
Fetch the last request for a path
method <String> - The request method for the requests you want to fetch
path <String> - The path of the requests you want to fetch
clearResponse(method, path)
Clear mocked response from the store
method <String> - The HTTP request method to clear saved response from
path <String> - The path to match against when clearing
clearResponses()
Clear all mocked responses from the store.
clearRequest(method, path)
Clear captured request from the store
method <String> - The HTTP request method to clear saved request from
path <String> - The path to match against when clearing
clearRequests()
Clear all captured requests from the store.
stop()
Stop Simulado.
Mock Response Options
{
path: '/testPath',
path: /\/testPath/.*/, // Regex path
method: 'GET',
status: 200,
headers: {
'X-Custom-Header': 'Custom Header Value'
},
body: {
data: 'DATA'
},
conditionalHeaders: {
needMe: 'true'
},
conditionalBody: {
data: 'YouNeedThisData'
},
delay: 5000
}