mockjax-router
npm install mockjax-router
Build a mock API to use in your browser tests:
var mockjaxRouter = ; var router = ; var users = {};var lastUserId = -1; router; router;
Use it with jquery:
var $ = ; $;
api
var mockjaxRouter = ;var router = ; router;router;router;router;router;router;
path
- a path for the resource, usually a root relative path like/api/users
, but could also be an absolute URL. Can contain parameters, in the form of:paramName
, e.g./users/:userId
.
handlers
{ return response;}
request
- an object containing:method
- the method, one ofGET
,POST
, etc.url
- the url of the resourceparams
- an object containing the parameters taken from thepath
headers
- an object with the request headersbody
- body. if this was transmitted as JSON then this is parsed into a JS value.
response
- an object containing the following fields.statusCode
- the status code, if omitted then200
.headers
- an object with the response headers. Optional.body
- the body, if a JS object, then it is transmitted as JSON. Optional.
The response can be omitted too, giving a 200 OK
.