vue-resource-mock

A mock middleware for vue-resource
3,816 29
Install
npm install vue-resource-mock
Latest Version:0.0.11
Vue:2
License:MIT
Last Updated:Jul 17, 2018
Links: GitHub  ·  npm
Maintainer: noru

Vue-Resource-Mock

Vue 1.x Vue 2.x Build Status npm version

This package requires no specific version of Vue but vue-resource. It works for both Vue/Vue2 as the time of this writing.

Copy and modified from https://github.com/airtonix/vue-resource-mock

Open to PR/Issue :)

Usage

Install

After npm install vue-resource-mock --save-dev,

import Vue from 'vue'
import VueResource from 'vue-resource'
import VueResourceMock from 'vue-resource-mock'
import MockData from 'path/to/file'   // MockData syntax down below

Vue.use(VueResource)

if (devMode) { // don't use it on your production build
  Vue.use(VueResourceMock, MockData, /* { silent: true/false } */) // after use vue-resource
}

Mock data
export default {

  // basic mock
  ['GET */path/to/resource'] (pathMatch, query, request, passThrough) {
    // before respond, you can check the path and query parameters with `pathMatch` & `query`
    // powered by 'url-pattern' & 'qs'
    // https://www.npmjs.com/package/url-pattern
    // https://www.npmjs.com/package/qs

    // to pass through this mock, call the 4th parameter as a function, the return value will be ignored
    passThrough()

    let body = { /* whatever */ }
    return {
      body: body,
      status: 200,
      statusText: 'OK',
      headers: { /*headers*/ },
      delay: 500, // millisecond
    }
  },

  // shorthand mock
  ['PUT */path/to/resource']: https://github.com/noru/vue-resource-mock/blob/HEAD/200, // respond with only status code

  ['POST */path/to/resource']: https://github.com/noru/vue-resource-mock/blob/HEAD/{ /*whatever*/ } // respond with only body, status code = 200

}

TODO

  • Rewrite in typescript
  • UT

License

MIT

Related Packages

vue-resource-mock-api

A mock middleware for vue-resource

1,917 1
h3-proxy

A proxy event handler for h3, using proxyRequest.

141,147 17
stepci

Automated API Testing and Quality Assurance

140,730 1,872
http-vue-loader

Load .vue files directly from your html/js. No node.js environment, no build ste...

52,627 1,477
vue-cli-plugin-mock

A package for local mock data functionality

3,025 30

Version History

Version Released License
0.0.11 MIT
0.0.10 MIT
0.0.9 MIT
0.0.8 MIT
0.0.7 MIT