fix(core): static-query migration should not prompt if no queries are used (#30254)
Currently we always prompt when the static-query migration runs. This is not always needed because some applications do not even use `ViewChild` or `ContentChild` queries and it just causes confusion if developers need to decide on a migration strategy while there is nothing to migrate. In order to avoid this confusion, we no longer prompt for a strategy if there are no queries declared within the project. PR Close #30254
This commit is contained in:

committed by
Alex Rickabaugh

parent
04a9f28c3d
commit
4c12d742dc
@ -1367,5 +1367,22 @@ describe('static-queries migration with usage strategy', () => {
|
||||
expect(tree.readContent('/src/index.ts'))
|
||||
.toContain(`@${queryType}('test', { static: false }) query: any;`);
|
||||
});
|
||||
|
||||
it(`should not prompt for migration strategy if no @${queryType} query is used`, async() => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@Component({template: '<span #test></span>'})
|
||||
export class NoQueriesDeclared {
|
||||
}
|
||||
`);
|
||||
|
||||
const testModule = require('../migrations/static-queries/strategy_prompt');
|
||||
spyOn(testModule, 'promptForMigrationStrategy').and.callThrough();
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(testModule.promptForMigrationStrategy).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user