test infrastructure for a fake XMLHttpRequest object
npm install fake-xml-http-requestThis library provide a fake XMLHttpRequest object for testing browser-based
libraries. It is partially extracted (and in many places simplified) from
Sinon.JS and attempts to match the behavior of
XMLHttpRequest specification.
respond function that takes three arguments: a HTTP response status``javascript
// simulate successful response
import FakeXMLHttpRequest from "fake-xml-http-request";
let xhr = new FakeXMLHttpRequest();
xhr.respond(200, {"Content-Type": "application/json"}, '{"key":"value"}');
xhr.status; // 200
xhr.statusText; // "OK"
xhr.responseText; // '{"key":"value"}'
// simulate failed response
xhr = new FakeXMLHttpRequest();
xhr.abort();
`
There is no mechanism for swapping the native XMLHttpRequest or for
recording, finding, or playing back requests. Libraries using FakeXMLHttpRequest
should provide this behavior.
Run with:
```
karma start
In order to have a more open and welcoming community this project adheres to a code of conduct adapted from the contributor covenant.
Please adhere to this code of conduct in any interactions you have with this project's community. If you encounter someone violating these terms, please let a maintainer (@trek) know and we will address it as soon as possible.