@@ -1302,6 +1302,44 @@ describe('MatStepper', () => {
13021302 expect ( stepper . selectedIndex ) . toBe ( 1 ) ;
13031303 expect ( stepper . selected ) . toBeTruthy ( ) ;
13041304 } ) ;
1305+
1306+ describe ( 'stepper with lazy content' , ( ) => {
1307+ it ( 'should render the content of the selected step on init' , ( ) => {
1308+ const fixture = createComponent ( StepperWithLazyContent ) ;
1309+ const element = fixture . nativeElement ;
1310+ fixture . componentInstance . selectedIndex = 1 ;
1311+ fixture . detectChanges ( ) ;
1312+
1313+ expect ( element . textContent ) . not . toContain ( 'Step 1 content' ) ;
1314+ expect ( element . textContent ) . toContain ( 'Step 2 content' ) ;
1315+ expect ( element . textContent ) . not . toContain ( 'Step 3 content' ) ;
1316+ } ) ;
1317+
1318+ it ( 'should render the content of steps when the user navigates to them' , ( ) => {
1319+ const fixture = createComponent ( StepperWithLazyContent ) ;
1320+ const element = fixture . nativeElement ;
1321+ fixture . componentInstance . selectedIndex = 0 ;
1322+ fixture . detectChanges ( ) ;
1323+
1324+ expect ( element . textContent ) . toContain ( 'Step 1 content' ) ;
1325+ expect ( element . textContent ) . not . toContain ( 'Step 2 content' ) ;
1326+ expect ( element . textContent ) . not . toContain ( 'Step 3 content' ) ;
1327+
1328+ fixture . componentInstance . selectedIndex = 1 ;
1329+ fixture . detectChanges ( ) ;
1330+
1331+ expect ( element . textContent ) . toContain ( 'Step 1 content' ) ;
1332+ expect ( element . textContent ) . toContain ( 'Step 2 content' ) ;
1333+ expect ( element . textContent ) . not . toContain ( 'Step 3 content' ) ;
1334+
1335+ fixture . componentInstance . selectedIndex = 2 ;
1336+ fixture . detectChanges ( ) ;
1337+
1338+ expect ( element . textContent ) . toContain ( 'Step 1 content' ) ;
1339+ expect ( element . textContent ) . toContain ( 'Step 2 content' ) ;
1340+ expect ( element . textContent ) . toContain ( 'Step 3 content' ) ;
1341+ } ) ;
1342+ } ) ;
13051343} ) ;
13061344
13071345/** Asserts that keyboard interaction works correctly. */
@@ -1826,3 +1864,26 @@ class NestedSteppers {
18261864class StepperWithStaticOutOfBoundsIndex {
18271865 @ViewChild ( MatStepper ) stepper : MatStepper ;
18281866}
1867+
1868+
1869+ @Component ( {
1870+ template : `
1871+ <mat-vertical-stepper [selectedIndex]="selectedIndex">
1872+ <mat-step>
1873+ <ng-template matStepLabel>Step 1</ng-template>
1874+ <ng-template matStepContent>Step 1 content</ng-template>
1875+ </mat-step>
1876+ <mat-step>
1877+ <ng-template matStepLabel>Step 2</ng-template>
1878+ <ng-template matStepContent>Step 2 content</ng-template>
1879+ </mat-step>
1880+ <mat-step>
1881+ <ng-template matStepLabel>Step 3</ng-template>
1882+ <ng-template matStepContent>Step 3 content</ng-template>
1883+ </mat-step>
1884+ </mat-vertical-stepper>
1885+ `
1886+ } )
1887+ class StepperWithLazyContent {
1888+ selectedIndex = 0 ;
1889+ }
0 commit comments