mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user