Socket
Socket
Sign inDemoInstall

fake-xml-http-request

Package Overview
Dependencies
0
Maintainers
5
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    fake-xml-http-request

test infrastructure for a fake XMLHttpRequest object


Version published
Weekly downloads
295K
decreased by-1.84%
Maintainers
5
Install size
84.1 kB
Created
Weekly downloads
 

Changelog

Source

2.1.2

  • #59 Add default values for on* properties
  • #58 (chore) Update npm dependencies and remove deprecated packages

Readme

Source

FakeXMLHttpRequest Build Status

This 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.

Why not just use Sinon.JS?

Sinon includes much more than just a fake XHR object which is useful in situations where you may not need mocks, spies, stubs, or fake servers.

How to use it

In addition to matching the native XMLHttpRequest's API, FakeXMLHttpRequest adds a respond function that takes three arguments: a HTTP response status number, a headers object, and a text response body:

// 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.

Testing

Tests are written in QUnit and run through the Karma test runner.

Run with:

karma start

Code of Conduct

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.

FAQs

Last updated on 09 Mar 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc