@@ -29,16 +29,21 @@ import { setAngularAppTestingManifest } from './testing-utils';
2929
3030describe ( 'AngularServerApp' , ( ) => {
3131 let app : AngularServerApp ;
32+ let slowRouteHook : ( ( ) => void ) | undefined ;
3233
3334 @Component ( {
3435 selector : 'app-home' ,
3536 template : `Home works` ,
3637 } )
3738 class HomeComponent {
3839 constructor ( ) {
39- if ( inject ( ActivatedRoute ) . snapshot . data [ 'destroyApp' ] ) {
40+ const data = inject ( ActivatedRoute ) . snapshot . data ;
41+ if ( data [ 'destroyApp' ] ) {
4042 inject ( PlatformRef ) . destroy ( ) ;
4143 }
44+ if ( data [ 'slow' ] ) {
45+ slowRouteHook ?.( ) ;
46+ }
4247 }
4348 }
4449
@@ -86,6 +91,7 @@ describe('AngularServerApp', () => {
8691 { path : 'page-with-headers' , component : HomeComponent } ,
8792 { path : 'page-with-status' , component : HomeComponent } ,
8893 { path : 'page-destroy-app' , component : HomeComponent , data : { destroyApp : true } } ,
94+ { path : 'page-slow' , component : HomeComponent , data : { slow : true } } ,
8995 { path : 'redirect' , redirectTo : 'home' } ,
9096 { path : 'redirect-via-navigate' , component : RedirectComponent } ,
9197 {
@@ -335,34 +341,22 @@ describe('AngularServerApp', () => {
335341 let appDestroyed = false ;
336342 let destroySpy : jasmine . Spy | undefined ;
337343
338- @Component ( {
339- selector : 'app-slow' ,
340- template : 'Slow page' ,
341- } )
342- class SlowComponent {
343- constructor ( ) {
344- destroySpy = spyOn ( inject ( PlatformRef ) , 'destroy' ) . and . callThrough ( ) ;
345- const pendingTasks = inject ( PendingTasks ) ;
346- const removeTask = pendingTasks . add ( ) ;
347- inject ( DestroyRef ) . onDestroy ( ( ) => {
348- appDestroyed = true ;
349- removeTask ( ) ;
350- } ) ;
351- resolveTaskReady ( ) ;
352- }
353- }
344+ slowRouteHook = ( ) => {
345+ destroySpy = spyOn ( inject ( PlatformRef ) , 'destroy' ) . and . callThrough ( ) ;
346+ const pendingTasks = inject ( PendingTasks ) ;
347+ const removeTask = pendingTasks . add ( ) ;
348+ inject ( DestroyRef ) . onDestroy ( ( ) => {
349+ appDestroyed = true ;
350+ removeTask ( ) ;
351+ } ) ;
352+ resolveTaskReady ( ) ;
353+ } ;
354354
355355 try {
356- setAngularAppTestingManifest (
357- [ { path : 'slow' , component : SlowComponent } ] ,
358- [ { path : 'slow' , renderMode : RenderMode . Server } ] ,
359- ) ;
360-
361- const customApp = new AngularServerApp ( ) ;
362356 const controller = new AbortController ( ) ;
363- const request = new Request ( 'http://localhost/slow' , { signal : controller . signal } ) ;
357+ const request = new Request ( 'http://localhost/page- slow' , { signal : controller . signal } ) ;
364358
365- const handlePromise = customApp . handle ( request ) ;
359+ const handlePromise = app . handle ( request ) ;
366360
367361 // Wait until the component is instantiated and holding a pending task
368362 await taskReady ;
@@ -373,15 +367,15 @@ describe('AngularServerApp', () => {
373367
374368 await expectAsync ( handlePromise ) . toBeRejectedWithError (
375369 DOMException ,
376- / R e q u e s t f o r : h t t p : \/ \/ l o c a l h o s t \/ s l o w w a s a b o r t e d / ,
370+ / R e q u e s t f o r : h t t p : \/ \/ l o c a l h o s t \/ p a g e - s l o w w a s a b o r t e d / ,
377371 ) ;
378372
379373 // Wait for the macrotask queue to clear since platform destruction is scheduled via setTimeout(0)
380374 await setTimeout ( 0 ) ;
381375 expect ( destroySpy ) . toHaveBeenCalledTimes ( 1 ) ;
382376 expect ( appDestroyed ) . toBeTrue ( ) ;
383377 } finally {
384- setupManifest ( ) ;
378+ slowRouteHook = undefined ;
385379 }
386380 } ) ;
387381
@@ -417,6 +411,22 @@ describe('AngularServerApp', () => {
417411 expect ( removeEventListenerSpy ) . toHaveBeenCalledWith ( 'abort' , jasmine . any ( Function ) ) ;
418412 } ) ;
419413
414+ it ( 'should reject reading response body if request is aborted after handle() resolves but before rendering completes' , async ( ) => {
415+ const controller = new AbortController ( ) ;
416+ const response = await app . handle (
417+ new Request ( 'http://localhost/home' , { signal : controller . signal } ) ,
418+ ) ;
419+ expect ( response ) . not . toBeNull ( ) ;
420+
421+ controller . abort ( ) ;
422+
423+ await expectAsync ( response ?. text ( ) ) . toBeRejectedWithError (
424+ DOMException ,
425+ / R e q u e s t f o r : h t t p : \/ \/ l o c a l h o s t \/ h o m e w a s a b o r t e d / ,
426+ ) ;
427+ await setTimeout ( 0 ) ;
428+ } ) ;
429+
420430 it ( 'should return configured headers for pages with specific header settings' , async ( ) => {
421431 const response = await app . handle ( new Request ( 'http://localhost/page-with-headers' ) ) ;
422432 const headers = response ?. headers . entries ( ) ?? [ ] ;
0 commit comments