|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google LLC All Rights Reserved. |
| 4 | + * |
| 5 | + * Use of this source code is governed by an MIT-style license that can be |
| 6 | + * found in the LICENSE file at https://angular.io/license |
| 7 | + */ |
| 8 | + |
| 9 | +import {Component, forwardRef, ɵɵdefineNgModule, ɵɵgetComponentDepsFactory, ɵɵsetNgModuleScope} from '@angular/core'; |
| 10 | +import {ComponentType} from '@angular/core/src/render3'; |
| 11 | + |
| 12 | +describe('component dependencies in local compilation', () => { |
| 13 | + it('should compute correct set of dependencies when importing ng-modules directly', () => { |
| 14 | + @Component({selector: 'sub'}) |
| 15 | + class SubComponent { |
| 16 | + } |
| 17 | + |
| 18 | + class SubModule { |
| 19 | + static ɵmod = ɵɵdefineNgModule({type: SubModule}); |
| 20 | + } |
| 21 | + ɵɵsetNgModuleScope(SubModule, {exports: [SubComponent]}); |
| 22 | + |
| 23 | + @Component({}) |
| 24 | + class MainComponent { |
| 25 | + } |
| 26 | + |
| 27 | + class MainModule { |
| 28 | + static ɵmod = ɵɵdefineNgModule({type: MainModule}); |
| 29 | + } |
| 30 | + ɵɵsetNgModuleScope(MainModule, {imports: [SubModule], declarations: [MainComponent]}); |
| 31 | + |
| 32 | + const deps = ɵɵgetComponentDepsFactory(MainComponent as ComponentType<any>)(); |
| 33 | + |
| 34 | + expect(deps).toEqual(jasmine.arrayWithExactContents([SubComponent, MainComponent])); |
| 35 | + }); |
| 36 | + |
| 37 | + it('should compute correct set of dependencies when importing ng-modules with providers', () => { |
| 38 | + @Component({selector: 'sub'}) |
| 39 | + class SubComponent { |
| 40 | + } |
| 41 | + |
| 42 | + class SubModule { |
| 43 | + static ɵmod = ɵɵdefineNgModule({type: SubModule}); |
| 44 | + } |
| 45 | + ɵɵsetNgModuleScope(SubModule, {exports: [SubComponent]}); |
| 46 | + |
| 47 | + @Component({}) |
| 48 | + class MainComponent { |
| 49 | + } |
| 50 | + |
| 51 | + class MainModule { |
| 52 | + static ɵmod = ɵɵdefineNgModule({type: MainModule}); |
| 53 | + } |
| 54 | + ɵɵsetNgModuleScope( |
| 55 | + MainModule, |
| 56 | + {imports: [{ngModule: SubModule, providers: []}], declarations: [MainComponent]}); |
| 57 | + |
| 58 | + const deps = ɵɵgetComponentDepsFactory(MainComponent as ComponentType<any>)(); |
| 59 | + |
| 60 | + expect(deps).toEqual(jasmine.arrayWithExactContents([SubComponent, MainComponent])); |
| 61 | + }); |
| 62 | + |
| 63 | + it('should compute correct set of dependencies when importing ng-modules using forward ref', |
| 64 | + () => { |
| 65 | + @Component({selector: 'sub'}) |
| 66 | + class SubComponent { |
| 67 | + } |
| 68 | + |
| 69 | + class SubModule { |
| 70 | + static ɵmod = ɵɵdefineNgModule({type: SubModule}); |
| 71 | + } |
| 72 | + ɵɵsetNgModuleScope(SubModule, {exports: [forwardRef(() => SubComponent)]}); |
| 73 | + |
| 74 | + @Component({}) |
| 75 | + class MainComponent { |
| 76 | + } |
| 77 | + |
| 78 | + class MainModule { |
| 79 | + static ɵmod = ɵɵdefineNgModule({type: MainModule}); |
| 80 | + } |
| 81 | + ɵɵsetNgModuleScope(MainModule, { |
| 82 | + imports: [forwardRef(() => SubModule)], |
| 83 | + declarations: [forwardRef(() => MainComponent)] |
| 84 | + }); |
| 85 | + |
| 86 | + const deps = ɵɵgetComponentDepsFactory(MainComponent as ComponentType<any>)(); |
| 87 | + |
| 88 | + expect(deps).toEqual(jasmine.arrayWithExactContents([SubComponent, MainComponent])); |
| 89 | + }); |
| 90 | + |
| 91 | + it('should compute correct set of dependencies when importing ng-modules with providers using forward ref', |
| 92 | + () => { |
| 93 | + @Component({selector: 'sub'}) |
| 94 | + class SubComponent { |
| 95 | + } |
| 96 | + |
| 97 | + class SubModule { |
| 98 | + static ɵmod = ɵɵdefineNgModule({type: SubModule}); |
| 99 | + } |
| 100 | + ɵɵsetNgModuleScope(SubModule, {exports: [SubComponent]}); |
| 101 | + |
| 102 | + @Component({}) |
| 103 | + class MainComponent { |
| 104 | + } |
| 105 | + |
| 106 | + class MainModule { |
| 107 | + static ɵmod = ɵɵdefineNgModule({type: MainModule}); |
| 108 | + } |
| 109 | + ɵɵsetNgModuleScope(MainModule, { |
| 110 | + imports: [forwardRef(() => ({ngModule: SubModule, providers: []}))], |
| 111 | + declarations: [MainComponent] |
| 112 | + }); |
| 113 | + |
| 114 | + const deps = ɵɵgetComponentDepsFactory(MainComponent as ComponentType<any>)(); |
| 115 | + |
| 116 | + expect(deps).toEqual(jasmine.arrayWithExactContents([SubComponent, MainComponent])); |
| 117 | + }); |
| 118 | +}); |
0 commit comments