mocks: docs, examples, tests
This commit is contained in:
@ -1,9 +1,9 @@
|
||||
{
|
||||
"mocks": [
|
||||
{
|
||||
"route": "/one",
|
||||
"route": "/",
|
||||
"response": {
|
||||
"body": { "id": 1, "name": "whatever" }
|
||||
"body": "<h1>Welcome to the Mock Responses example</h1>"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -15,11 +15,11 @@
|
||||
},
|
||||
{
|
||||
"route": "/three",
|
||||
"targets": [
|
||||
"responses": [
|
||||
{
|
||||
"request": { "method": "GET" },
|
||||
"response": {
|
||||
"body": { "id": 1, "name": "whatever" }
|
||||
"body": "<h1>Mock response for 'GET' request on /three</h1>"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -1,7 +0,0 @@
|
||||
body {
|
||||
background-color: #AA3939;
|
||||
color: #FFE2E2
|
||||
}
|
||||
svg {
|
||||
fill: #000
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
<head>
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
</head>
|
||||
<h1>Mock responses</h1>
|
||||
<ul>
|
||||
<li>list data</li>
|
||||
</ul>
|
||||
<script src="bundle.js"></script>
|
@ -1,9 +0,0 @@
|
||||
'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('')
|
||||
})
|
3
example/mock/mocks/data.json
Normal file
3
example/mock/mocks/data.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"one": "static data"
|
||||
}
|
@ -1,8 +1,5 @@
|
||||
module.exports = {
|
||||
response: function (ctx, id, name) {
|
||||
this.body = {
|
||||
id: id,
|
||||
name: name
|
||||
}
|
||||
ctx.body = `<h1>id: ${id}, name: ${name}</h1>`
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
const fs = require('fs')
|
||||
|
||||
module.exports = {
|
||||
response: {
|
||||
body: { id: 2, name: 'eucalyptus', maxHeight: 210 }
|
||||
body: fs.createReadStream(__filename)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user