@@ -385,6 +385,49 @@ describe('runtime code migration', () => {
385385 ) ;
386386 } ) ;
387387
388+ it ( 'should not replace imports from non selected components' , async ( ) => {
389+ declareLibrarySymbols ( 'legacy-button' , 'export declare class MatLegacyButtonModule {};' ) ;
390+ declareLibrarySymbols ( 'legacy-checkbox' , 'export declare class MatLegacyCheckboxModule {};' ) ;
391+
392+ await runMigrationTest (
393+ `
394+ import {NgModule} from '@angular/core';
395+ import {MatLegacyButtonModule} from '@angular/material/legacy-button';
396+ import {MatLegacyCheckboxModule} from '@angular/material/legacy-checkbox';
397+
398+ @NgModule({imports: [MatLegacyButtonModule, MatLegacyCheckboxModule]})
399+ export class AppModule {}
400+ ` ,
401+ `
402+ import {NgModule} from '@angular/core';
403+ import {MatButtonModule} from '@angular/material/button';
404+ import {MatLegacyCheckboxModule} from '@angular/material/legacy-checkbox';
405+
406+ @NgModule({imports: [MatButtonModule, MatLegacyCheckboxModule]})
407+ export class AppModule {}
408+ ` ,
409+ ) ;
410+ } ) ;
411+
412+ it ( 'should always replace legacy-core imports even if they are not specified' , async ( ) => {
413+ await runMigrationTest (
414+ `
415+ import {NgModule} from '@angular/core';
416+ import {MatLegacyOptionModule as MatOptionModule, LEGACY_VERSION as VERSION} from '@angular/material/legacy-core';
417+
418+ @NgModule({imports: [MatOptionModule]})
419+ export class AppModule {}
420+ ` ,
421+ `
422+ import {NgModule} from '@angular/core';
423+ import {MatOptionModule, VERSION} from '@angular/material/core';
424+
425+ @NgModule({imports: [MatOptionModule]})
426+ export class AppModule {}
427+ ` ,
428+ ) ;
429+ } ) ;
430+
388431 it ( 'should migrate styles for a component' , async ( ) => {
389432 await runMigrationTest (
390433 `
0 commit comments