vrm

vue-resource-mock

Backend mocking for rapid project testing and previews

Showing:

Popularity

Downloads/wk

171

GitHub Stars

28

Maintenance

Last Commit

3yrs ago

Contributors

9

Package

Dependencies

2

Size (min+gzip)

5.9KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

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']: 200, // respond with only status code

  ['POST */path/to/resource']: { /*whatever*/ } // respond with only body, status code = 200

}

TODO

  • Rewrite in typescript
  • UT

License

MIT

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100