XHR Mocking Utility
JSON →XHR-mock is a JavaScript utility designed for intercepting and mocking `XMLHttpRequest` objects, primarily for testing purposes or for front-end development against an unbuilt backend. It allows developers to define mock responses for specific HTTP methods and URLs, enabling reliable and isolated unit and integration tests for code that relies on browser-native `XMLHttpRequest` or libraries built upon it, such as Axios, jQuery, and Superagent. The current stable version is 2.5.1. The library is actively maintained with periodic updates and improvements, demonstrated by its progression through several minor and major versions since its initial release. A key differentiator is its ability to operate seamlessly in both Node.js environments (for server-side testing) and browser environments, while maintaining compliance with the WHATWG XHR specification. It offers a simple API for setting up global mocks and ensuring proper cleanup, which is crucial for preventing test pollution.
Traffic · last 30 days ↑0% vs prev 7d
top countries 🇺🇸 United States · 🇨🇦 Canada · 🇩🇪 Germany · 🇫🇷 France