httpbackend is an npm module designed to mock HTTP requests specifically within an AngularJS application being tested by Protractor. Its primary function is to intercept `XMLHttpRequest` and `$http` requests made by the AngularJS application, allowing developers to define custom responses for specific URLs and methods. This facilitates isolated and deterministic testing of frontend logic without relying on a live backend server. The package is currently at version 2.0.0, last published in June 2017. Due to its tight coupling with AngularJS and Protractor, both of which are considered legacy technologies, the package is no longer actively maintained. Its release cadence was sporadic and has ceased, making it unsuitable for modern web development workflows involving current Angular versions (2+), React, Vue, or contemporary testing frameworks like Cypress or Playwright. Its key differentiator was its direct integration with Protractor's `browser` object for injecting mock modules into AngularJS applications.
npm install httpbackendVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `httpbackend` with Protractor to mock both GET and POST requests, providing predefined responses for isolated testing of an AngularJS application's frontend logic.
For new projects or migration, consider using native mock features of modern testing frameworks (e.g., Cypress intercept, Playwright route, Jest mocks) or dedicated HTTP mocking libraries designed for current frameworks.
Use CommonJS `require()` syntax: `const HttpBackend = require('httpbackend');`.Ensure `bower_components/angular-mocks/angular-mocks.js` (or equivalent) is loaded in your test application's HTML. Example: `<script src="/bower_components/angular-mocks/angular-mocks.js"></script>`.
No direct fix for the package itself. It is recommended to use actively maintained alternatives tailored for modern web development practices and frameworks.
Ensure your test is running within a Protractor environment where the `browser` object is automatically provided. If not, you might need to manually require Protractor and assign `protractor.browser`.
Verify `angular-mocks.js` is included in your application under test. Ensure your Protractor `onPrepare` function correctly configures the mock module loading without conflicting with the app's initial bootstrapping.
Double-check the method (GET, POST, PUT, etc.) and URL pattern provided to `backend.whenGET(/regex/)` or `backend.whenGET('/exact/path')` against the actual request made by your AngularJS application. Use regular expressions for more flexible matching.