A Vue.js project with mock-server and unit-test
- header
- comment
- address-select
- image-slider
- qrcode
- loading-bar
- chart
- waiting for ...
- toast
we use json-server
to get a full fake REST API, use mock.js to build mock data ( as local database :) ), for example:
// db.js
var Mock = require('mockjs');
module.exports = {
project_comments: Mock.mock({
"error": 0,
"message": "success",
"result|40": [{
"author": "@name",
"comment": "@cparagraph",
"date": "@datetime"
}]
}),
push_comment: Mock.mock({
"error": 0,
"message": "success",
"result": []
})
};
// routes.json
{
"/project/:page/comments.action": "/project_comments?_page=:page&_limit=5",
"/comment/add.action": "/push_comment"
}
test components and vuex( include mutations
actions
getters
), test result:
# install dependencies
npm install
# serve with hot reload at localhost:8181
npm run dev
# run mock server at localhost:3000
npm run mock
# run unit test
npm run test
# build for production with minification
npm run build
- add
vuex
to manage app state - add unit test
- refresh the mock server after modifying
mock/db.js