1.1.0 • Published 3 years ago

xhr-fake v1.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Framework for XHR fake

fake specified request with specified response at any time,and you can get the real request parameters

supports:

  • XMLHttpRequest
  • ajax request
  • fetch request

Why

current xhr interceptors can modify response after send request to server. but sometimes we don't want to send request to server. so we create a new pakcage witch is a fake rather than a interceptor, meaning we don't want to send request to server

How to use

import xhr from 'xhr-fake';

...

const fake = xhr.fake((url,_body)=>/api\/caculate/.test(url + ''), (_request) => ({ 
    status:200,
    body: JSON.stringify({ result: 27 }) 
}));

//trigger the xhr|ajax|fetch request ,but the request will not be sent to the server
document.getElementById('caculateBtn').click();

const request = await fake.getRequest(3*1000);

test in browser

cd test-browser
npm run dev

open http://localhost:3000/ and run test

1.0.2

3 years ago

1.1.0

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago