GithubHelp home page GithubHelp logo

izelnakri / fakexmlhttprequest Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pretenderjs/fakexmlhttprequest

0.0 1.0 0.0 401 KB

A fake XMLHttpRequest object for testing in browsers

License: MIT License

JavaScript 100.00%

fakexmlhttprequest's Introduction

FakeXMLHttpRequest Build Status npm version

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.

fakexmlhttprequest's People

Contributors

trek avatar xg-wang avatar eventualbuddha avatar bantic avatar mike-north avatar stefanpenner avatar sandersky avatar dependabot[bot] avatar givanse avatar raido avatar cowboyd avatar zeppelin avatar thejchap avatar kturney avatar maxmurdoch avatar cibernox avatar rwjblue avatar ohcibi avatar alexclarkofficial avatar simonihmig avatar yamadapc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.