mock responses.. example

This commit is contained in:
Lloyd Brookes
2015-11-18 16:37:16 +00:00
parent aab1f04a2f
commit 9f5f969205
10 changed files with 104 additions and 10 deletions

View File

@ -0,0 +1,6 @@
{
"rewrite": [
{ "from": "/tree", "to": "/mocks/trees.mock.js" },
{ "from": "/tree/:id", "to": "/mocks/tree.mock.js" }
]
}

View File

@ -0,0 +1,7 @@
body {
background-color: #AA3939;
color: #FFE2E2
}
svg {
fill: #000
}

8
example/mock/index.html Normal file
View File

@ -0,0 +1,8 @@
<head>
<link rel="stylesheet" href="css/style.css">
</head>
<h1>Mock responses</h1>
<ul>
<li>list data</li>
</ul>
<script src="bundle.js"></script>

9
example/mock/index.js Normal file
View File

@ -0,0 +1,9 @@
'use strict'
const request = require('req-then')
const $ = document.querySelector.bind(document)
request('http://localhost:8000/tree').then(response => {
$('ul').innerHTML = JSON.parse(response.data).map(tree => {
return `<li>${tree.name}</li>`
}).join('')
})

View File

@ -0,0 +1,8 @@
module.exports = [
{
response: {
status: 200,
body: { id: 2, name: 'eucalyptus', maxHeight: 210 }
}
}
]

View File

@ -0,0 +1,23 @@
module.exports = [
{
request: {
method: 'GET'
},
response: {
status: 200,
body: [
{ id: 1, name: 'conifer', maxHeight: 115 },
{ id: 2, name: 'eucalyptus', maxHeight: 210 }
]
}
},
{
request: {
method: 'POST'
},
response: {
status: 201,
location: '/tree/1'
}
}
]