A jQuery plugin for mocking or simulating AJAX requests and responses in JavaScript applications.
jQuery Mockjax is a plugin that intercepts AJAX requests made with jQuery and returns mocked responses. It allows developers to simulate backend API behavior during frontend development and testing, eliminating the need for a live server. The plugin supports matching requests by URL, method, and data, and can generate dynamic responses with configurable latency and HTTP statuses.
Frontend developers using jQuery who need to test AJAX-dependent features, prototype applications without a backend, or create reliable unit tests for client-side code.
Developers choose Mockjax because it integrates transparently with jQuery's native AJAX handling, requires no modifications to production code, and offers extensive flexibility in defining request matches and responses. Its simplicity and power make it a go-to tool for mocking AJAX in jQuery-based projects.
The jQuery Mockjax Plugin provides a simple and extremely flexible interface for mocking or simulating ajax requests and responses
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Intercepts $.ajax() transparently without modifying production code, as it replaces the native method with a mock-aware wrapper, ensuring compatibility with existing jQuery workflows.
Supports URL matching with strings, wildcards, regex, plus HTTP methods and data inspection, allowing precise control over which requests to mock, as detailed in the 'Defining a Request to Match' section.
Enables setting response times, HTTP statuses, and generating responses via callbacks, useful for testing edge cases like errors and latency, with examples for simulating timeouts and random delays.
Provides methods to add, clear, and inspect mock handlers individually or globally, facilitating easy test setup and teardown, as shown in the 'Removing Mockjax Handlers' section.
Exclusively works with jQuery's AJAX method, making it irrelevant for projects using modern alternatives like the Fetch API or other libraries, which limits its applicability in contemporary frontend development.
For JSON and XML responses, older browsers may require external libraries like json2.js or xmlDOM, adding complexity and potential bloat, as noted in the 'Data Types Available for Mocking' section.
Version 2 introduced minor breaking changes, necessitating careful migration from older versions, which can disrupt existing test suites and require manual adjustments, as warned in the README introduction.
Lacks native TypeScript definitions, forcing developers to rely on community contributions or manual typings for type-safe usage, which is a drawback in modern, type-heavy development environments.