File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -391,6 +391,14 @@ class HttpResourceImpl<T>
391
391
this . client = injector . get ( HttpClient ) ;
392
392
}
393
393
394
+ override set ( value : T ) : void {
395
+ super . set ( value ) ;
396
+
397
+ this . _headers . set ( undefined ) ;
398
+ this . _progress . set ( undefined ) ;
399
+ this . _statusCode . set ( undefined ) ;
400
+ }
401
+
394
402
// This is a type only override of the method
395
403
declare hasValue : ( ) => this is HttpResourceRef < Exclude < T , undefined > > ;
396
404
}
Original file line number Diff line number Diff line change @@ -319,4 +319,19 @@ describe('httpResource', () => {
319
319
req = backend . expectOne ( '/data' ) ;
320
320
req . flush ( [ ] ) ;
321
321
} ) ;
322
+
323
+ it ( 'should reset past request data when using set()' , async ( ) => {
324
+ const backend = TestBed . inject ( HttpTestingController ) ;
325
+ const res = httpResource ( ( ) => '/data' , { injector : TestBed . inject ( Injector ) } ) ;
326
+ TestBed . tick ( ) ;
327
+ const req = backend . expectOne ( '/data' ) ;
328
+ req . flush ( [ ] ) ;
329
+ await TestBed . inject ( ApplicationRef ) . whenStable ( ) ;
330
+
331
+ res . set ( [ ] ) ;
332
+
333
+ expect ( res . headers ( ) ) . toBe ( undefined ) ;
334
+ expect ( res . progress ( ) ) . toBe ( undefined ) ;
335
+ expect ( res . statusCode ( ) ) . toBe ( undefined ) ;
336
+ } ) ;
322
337
} ) ;
You can’t perform that action at this time.
0 commit comments