ajax-mock-bar
AJAX/XHR mock bar - change mockups runtime.
Last updated 3 years ago by newton_ .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ajax-mock-bar 
SYNC missed versions from official npm registry.

ajax-mock-bar

AJAX/XHR mock bar - change mockups runtime.

Installation

npm install --save ajax-mock-bar

The UMD build is in the dist directory.

Description

This is a debug menu for choosing between mocks runtime.

Debug menu screenshot

It's intended to fully mock the XMLHTTPRequest class in browsers. You can use any ajax function/lib/framework for your project. Just write your config for XHR mocks and switch them while testing.

You don't need a server to write the client.

Configuration

let config = {
    folder1: [
        {
            // All of the following are optional:
            
            name: 'Test', // Uses the path for default name
            host: /.*/, // Also accept strings for explicit check
            path: /^\/test$/, // Also accept strings for explicit check
            filter: ({method, url, headers, body}) => true,
            

            response: {
                default: {
                    // All props are optional
                    status: 200,
                    headers: {},
                    type: 'json',
                    body: {
                        foo: 'bar'
                    },
                    size: 1024
                },

                timeout: {
                    timeout: 2000,
                    error: 'timeout'
                },

                error: {
                    timeout: 1000,
                    error: 'error'
                },

                fn: ({method, url, headers, body}) => ({
                    status: 200,
                    headers: {},
                    type: 'json',
                    body: {
                        foo: 'bar'
                    },
                    size: 1024
                })
            }
        }
    ],
    
    folder2: [
        // ...
    ]
};
const AjaxMockBar = require('ajax-mock-bar');

let bar = new AjaxMockBar(config);
document.body.appendChild(bar.container);
// or attach it where ever you want, it's fixed position

bar.start();

Current Tags

  • 1.0.4                                ...           latest (3 years ago)

5 Versions

  • 1.0.4                                ...           3 years ago
  • 1.0.3                                ...           4 years ago
  • 1.0.2                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |