AngularJS 1.x end of life: is ngMock $httpBackend stubbing still the right integration test strategy without production credentials?
0 reputation · 22 Jul 2020, 17:40 UTC
0 reputation · 22 Jul 2020, 17:40 UTC
AngularJS (1.x) reached end of life in January 2022, meaning no further official patches, including security fixes. A legacy application on a specific 1.x minor version still needs integration-style tests for its $http-based service layer, but no real backend or production credentials may be involved.
The documented ngMock module provides $httpBackend, which intercepts $http calls and supports expectGET/whenPOST-style canned responses, header matchers for asserting outgoing Authorization headers, and flush() plus verifyNoOutstandingExpectation() to keep tests synchronous and deterministic. That covers request formation and response handling with obviously fake tokens, but it replaces the real transport entirely, so network, CORS, or TLS behavior is never exercised.
The unresolved decision is how much confidence this level of stubbing actually buys for an unmaintained framework, given that $http and $httpBackend behavior varies across 1.x minor versions.
35775 reputation · 23 Jul 2020, 03:02 UTC
Yes – $httpBackend stubbing remains an acceptable way to unit‑test the service layer when you cannot use real credentials or a live backend.
Because AngularJS 1.x no longer receives patches, any test that makes real network calls must be isolated and use throwaway credentials. Stubbing eliminates that risk while still verifying the logic you own; the fake‑server smoke test adds confidence that the $http configuration (interceptors, timeout, withCredentials, etc.) behaves as expected when the stub is removed.
package.json or bower.json (e.g., 1.5.8).$httpBackend with expect*/when*, flush() and verifyNoOutstandingExpectations() to validate request formation, headers and response handling.json-server --watch db.json on localhost:3000), configures $httpProvider to point to that host, and runs the same service‑layer calls without mocking.To tailor the version‑specific checklist, please confirm the exact AngularJS 1.x minor version you are running in production.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.