From ed51ecd95cd2bc32ea0d9ca928a3166114cc048b Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Wed, 21 Sep 2022 11:36:05 +0200 Subject: [PATCH] test(upgrade): demonstrate that upgraded component can be standalone (#47503) This change is adding a test demonstrating that AngularJS component can be upgraded to a standalone directive. PR Close #47503 --- .../integration/upgrade_component_spec.ts | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/packages/upgrade/static/test/integration/upgrade_component_spec.ts b/packages/upgrade/static/test/integration/upgrade_component_spec.ts index 16c3e300852..e6e6760eaf4 100644 --- a/packages/upgrade/static/test/integration/upgrade_component_spec.ts +++ b/packages/upgrade/static/test/integration/upgrade_component_spec.ts @@ -4293,5 +4293,46 @@ withEachNg1Version(() => { .toBe('ng2A(ng1A(ng2B(ng1B(^^ng1A: ng1A | ?^^ng1B: | ^ng1B: ng1B))))'); }); })); + + describe('standalone', () => { + it('should upgrade to a standalone component in NgModule-bootstrapped application', + waitForAsync(() => { + const ng1Component: angular.IComponent = {template: `I'm from AngularJS!`}; + + // Define `Ng1ComponentFacade` (standalone) + @Directive({selector: 'ng1', standalone: true}) + class Ng1ComponentStandaloneFacade extends UpgradeComponent { + constructor(elementRef: ElementRef, injector: Injector) { + super('ng1', elementRef, injector); + } + } + + // Define `Ng2Component` + @Component({selector: 'ng2', template: ''}) + class Ng2Component { + } + + // Define `ng1Module` + const ng1Module = angular.module_('ng1Module', []) + .component('ng1', ng1Component) + .directive('ng2', downgradeComponent({component: Ng2Component})); + + // Define `Ng2Module` + @NgModule({ + declarations: [Ng2Component], + imports: [BrowserModule, UpgradeModule, Ng1ComponentStandaloneFacade] + }) + class Ng2Module { + ngDoBootstrap() {} + } + + // Bootstrap + const element = html(``); + + bootstrap(platformBrowserDynamic(), Ng2Module, element, ng1Module).then(() => { + expect(multiTrim(element.textContent)).toBe(`I'm from AngularJS!`); + }); + })); + }); }); });