tammy-mock

1.0.4 • Public • Published

Tammy // mock

npm package

Note: mock for tammy or axios

NPM version NPM Downloads


Installation

Load tammy via classical <script> tag

<script src="//cdn.jsdelivr.net/npm/tammy/umd.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/tammy-mock/umd.min.js"></script>
const mock = new TammyMock();
mock.get('/api/test', (req, res) => {
  res.json({
    code: 0,
    message: 'success'
  });
});
tammy.http.defaults.adapter = mock.getAdapter();
http('/api/test')
  .then(function(res) {
 
  });

CommonJS style with npm

npm install tammy --save
 
# mock 
npm install tammy-mock --save
 
// es6
import { http } from 'tammy';
import Mock from 'tammy-mock';
 
const mock = new Mock();
mock.get('/api/test', (req, res) => {
  res.json({
    code: 0,
    message: 'success'
  });
});
http.defaults.adapter = mock.getAdapter();
http('/api/test')
  .then(function(res) {
 
  });
 

API

  • use(fn)
  • all(path, ...fns)
  • head(path, ...fns)
  • options(path, ...fns)
  • get(path, ...fns)
  • put(path, ...fns)
  • patch(path, ...fns)
  • post(path, ...fns)
  • delete(path, ...fns)
  • del(path, ...fns)

req

  • url
  • method
  • path
  • headers
  • query
  • body
  • xhr
  • header(name)
  • getHeader(name)
  • get(name)

res

  • req
  • headers
  • type(type)
  • header(name, value)
  • set(name, value)
  • setHeader(name, value)
  • get(name)
  • getHeader(name)
  • removeHeader(name)
  • status(code)
  • send(body)
  • json(obj)

Readme

Keywords

Package Sidebar

Install

npm i tammy-mock

Weekly Downloads

1

Version

1.0.4

License

MIT

Unpacked Size

150 kB

Total Files

6

Last publish

Collaborators

  • fengxinming