fix(http): Reset headers, progress, and statusCode when using set() in HttpResource (#62873)

Currently, those values aren't reset, which means they are out of sync with the new value

PR Close #62873
This commit is contained in:
Vincent
2025-07-29 16:11:32 +02:00
committed by Jessica Janiuk
parent 216d883074
commit ae443f8eb0
2 changed files with 23 additions and 0 deletions
+8
View File
@@ -391,6 +391,14 @@ class HttpResourceImpl<T>
this.client = injector.get(HttpClient);
}
override set(value: T): void {
super.set(value);
this._headers.set(undefined);
this._progress.set(undefined);
this._statusCode.set(undefined);
}
// This is a type only override of the method
declare hasValue: () => this is HttpResourceRef<Exclude<T, undefined>>;
}
@@ -319,4 +319,19 @@ describe('httpResource', () => {
req = backend.expectOne('/data');
req.flush([]);
});
it('should reset past request data when using set()', async () => {
const backend = TestBed.inject(HttpTestingController);
const res = httpResource(() => '/data', {injector: TestBed.inject(Injector)});
TestBed.tick();
const req = backend.expectOne('/data');
req.flush([]);
await TestBed.inject(ApplicationRef).whenStable();
res.set([]);
expect(res.headers()).toBe(undefined);
expect(res.progress()).toBe(undefined);
expect(res.statusCode()).toBe(undefined);
});
});