@@ -149,6 +149,47 @@ describe('router outlet name', () => {
149149 advance ( fixture ) ;
150150 expect ( fixture . nativeElement . innerHTML ) . toMatch ( '.*component 3.*component 2.*component 1' ) ;
151151 } ) ) ;
152+
153+ it ( 'should not activate if route is changed' , fakeAsync ( ( ) => {
154+ @Component ( {
155+ standalone : true ,
156+ template : '<div *ngIf="initDone"><router-outlet></router-outlet></div>' ,
157+ imports : [ RouterOutlet , CommonModule ] ,
158+ } )
159+ class ParentCmp {
160+ initDone = false ;
161+ constructor ( ) {
162+ setTimeout ( ( ) => this . initDone = true , 1000 ) ;
163+ }
164+ }
165+
166+ @Component ( {
167+ template : 'child component' ,
168+ standalone : true ,
169+ } )
170+ class ChildCmp {
171+ }
172+
173+ TestBed . configureTestingModule ( {
174+ imports : [ RouterTestingModule . withRoutes ( [
175+ { path : 'parent' , component : ParentCmp , children : [ { path : 'child' , component : ChildCmp } ] }
176+ ] ) ]
177+ } ) ;
178+ const router = TestBed . inject ( Router ) ;
179+ const fixture = createRoot ( router , ParentCmp ) ;
180+
181+ advance ( fixture , 250 ) ;
182+ router . navigate ( [ 'parent/child' ] ) ;
183+ advance ( fixture , 250 ) ;
184+ // Not contain because initDone is still false
185+ expect ( fixture . nativeElement . innerHTML ) . not . toContain ( 'child component' ) ;
186+
187+ advance ( fixture , 1500 ) ;
188+ router . navigate ( [ 'parent' ] ) ;
189+ advance ( fixture , 1500 ) ;
190+ // Not contain because route was changed back to parent
191+ expect ( fixture . nativeElement . innerHTML ) . not . toContain ( 'child component' ) ;
192+ } ) ) ;
152193} ) ;
153194
154195function advance ( fixture : ComponentFixture < unknown > , millis ?: number ) : void {
0 commit comments