Not a Propaganda Machine
Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »

response-injection

0.0.0 • Public • Published

Response Injection

description

inject custom Response to XHR from Service Worker.

POF of mocking networks access from browser in testing.

how to use

Injector(
// response mock data
{
  '/success': {
    head: {
      status: 200,
      statusText: 'OK',
      headers: {
        'Content-Type': 'application/json'
      }
    },
    body: {
      id: 200,
      name: 'jxck',
      mail: 'jxck@example.com'
    }
  },
  '/fail': {
    head: {
      status: 404,
      statusText: 'Not Found',
      headers: {
        'Content-Type': 'application/json'
      }
    },
    body: {
      message: 'user not found'
    }
  }
},
 
// option
{
  ignore: ['/', '/test.js', '/main.js'], // ignore injection (default [])
  scope: '.' // scope for register worker (default '/')
}
 
).then(
 
// write test as usual
function test() {
  console.log('start test');
 
  get('/success').then(function(res) {
    console.assert(res.id, 200);
  }).catch(function(err) {
    console.assert(false);
  });
 
  get('/fail').then(function(res) {
    console.assert(false);
  }).catch(function(err) {
    console.assert(err.message, 'user not found');
  });
 
  // etc
}
 
).catch(console.error.bind(console));

TODO

  • write test
  • write more readme

License

The MIT License (MIT) Copyright (c) 2013 Jxck

install

npm i response-injection

Downloadsweekly downloads

2

version

0.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability