Skip to content

noru/vue-resource-mock

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Backend mocking for rapid project testing and previews

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 90.3%
  • Shell 9.7%
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy