From b48dd52494adb0564a472044b42a9cbc06c42674 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Tue, 27 Aug 2019 17:40:55 +0200 Subject: [PATCH] test: add integration test for missing-injectable migration (#32349) Adds a new test to the `ng_update_migrations` that ensures that the `missing-injectable` migration works properly in a real CLI project. Additionally this ensures that the `missing-injectable` and `undecorated-classes-with-di` migrations play nicely together. PR Close #32349 --- .../migration-tests/providers-test-module.ts | 31 ++++++++++++++++ .../providers-test-module_expected.ts | 35 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 integration/ng_update_migrations/src/app/migration-tests/providers-test-module.ts create mode 100644 integration/ng_update_migrations/src/app/migration-tests/providers-test-module_expected.ts diff --git a/integration/ng_update_migrations/src/app/migration-tests/providers-test-module.ts b/integration/ng_update_migrations/src/app/migration-tests/providers-test-module.ts new file mode 100644 index 0000000000..3c0e65522f --- /dev/null +++ b/integration/ng_update_migrations/src/app/migration-tests/providers-test-module.ts @@ -0,0 +1,31 @@ +import {Directive, NgModule, NgZone} from '@angular/core'; + +export class TypeCase {} + +// undecorated-classes-with-di migration will add "@Injectable" here +// because the constructor is inherited in "ProvideCase". +class BaseProviderCase { + constructor(zone: NgZone) {} +} + +export class ProvideCase extends BaseProviderCase {} + +export class ProviderClass {} + +export class DontNeedCase {} + +@Directive() +export class DirectiveCase {} + +@NgModule({ + providers: [ + TypeCase, + {provide: ProvideCase}, + {provide: DontNeedCase, useValue: 0}, + {provide: DontNeedCase, useFactory: () => null}, + {provide: DontNeedCase, useExisting: TypeCase}, + {provide: DontNeedCase, useClass: ProviderClass}, + DirectiveCase, + ] +}) +export class ProvidersTestModule {} diff --git a/integration/ng_update_migrations/src/app/migration-tests/providers-test-module_expected.ts b/integration/ng_update_migrations/src/app/migration-tests/providers-test-module_expected.ts new file mode 100644 index 0000000000..9faa5120d1 --- /dev/null +++ b/integration/ng_update_migrations/src/app/migration-tests/providers-test-module_expected.ts @@ -0,0 +1,35 @@ +import { Directive, NgModule, NgZone, Injectable } from '@angular/core'; + +@Injectable() +export class TypeCase {} + +// undecorated-classes-with-di migration will add "@Injectable" here +// because the constructor is inherited in "ProvideCase". +@Injectable() +class BaseProviderCase { + constructor(zone: NgZone) {} +} + +@Injectable() +export class ProvideCase extends BaseProviderCase {} + +@Injectable() +export class ProviderClass {} + +export class DontNeedCase {} + +@Directive() +export class DirectiveCase {} + +@NgModule({ + providers: [ + TypeCase, + {provide: ProvideCase}, + {provide: DontNeedCase, useValue: 0}, + {provide: DontNeedCase, useFactory: () => null}, + {provide: DontNeedCase, useExisting: TypeCase}, + {provide: DontNeedCase, useClass: ProviderClass}, + DirectiveCase, + ] +}) +export class ProvidersTestModule {}