1- import {
2- inject ,
3- fakeAsync ,
4- flushMicrotasks ,
5- TestComponentBuilder ,
6- TestBed ,
7- async ,
8- } from '@angular/core/testing' ;
9- import { Component , ViewChild , ViewContainerRef } from '@angular/core' ;
1+ import { inject , fakeAsync , flushMicrotasks , TestBed , async } from '@angular/core/testing' ;
2+ import { NgModule , Component , ViewChild , ViewContainerRef } from '@angular/core' ;
103import { TemplatePortalDirective , PortalModule } from '../portal/portal-directives' ;
114import { TemplatePortal , ComponentPortal } from '../portal/portal' ;
125import { Overlay } from './overlay' ;
@@ -18,36 +11,32 @@ import {OverlayModule} from './overlay-directives';
1811
1912
2013describe ( 'Overlay' , ( ) => {
21- let builder : TestComponentBuilder ;
2214 let overlay : Overlay ;
2315 let componentPortal : ComponentPortal < PizzaMsg > ;
2416 let templatePortal : TemplatePortal ;
2517 let overlayContainerElement : HTMLElement ;
2618
2719 beforeEach ( async ( ( ) => {
2820 TestBed . configureTestingModule ( {
29- imports : [ OverlayModule , PortalModule ] ,
30- declarations : [ TestComponentWithTemplatePortals , PizzaMsg ] ,
21+ imports : [ OverlayModule , PortalModule , OverlayTestModule ] ,
3122 providers : [
3223 { provide : OverlayContainer , useFactory : ( ) => {
3324 overlayContainerElement = document . createElement ( 'div' ) ;
3425 return { getContainerElement : ( ) => overlayContainerElement } ;
3526 } }
3627 ]
3728 } ) ;
38- } ) ) ;
3929
30+ TestBed . compileComponents ( ) ;
31+ } ) ) ;
4032
41- let deps = [ TestComponentBuilder , Overlay ] ;
42- beforeEach ( fakeAsync ( inject ( deps , ( tcb : TestComponentBuilder , o : Overlay ) => {
43- builder = tcb ;
33+ beforeEach ( fakeAsync ( inject ( [ Overlay ] , ( o : Overlay ) => {
4434 overlay = o ;
4535
46- builder . createAsync ( TestComponentWithTemplatePortals ) . then ( fixture => {
47- fixture . detectChanges ( ) ;
48- templatePortal = fixture . componentInstance . templatePortal ;
49- componentPortal = new ComponentPortal ( PizzaMsg , fixture . componentInstance . viewContainerRef ) ;
50- } ) ;
36+ let fixture = TestBed . createComponent ( TestComponentWithTemplatePortals ) ;
37+ fixture . detectChanges ( ) ;
38+ templatePortal = fixture . componentInstance . templatePortal ;
39+ componentPortal = new ComponentPortal ( PizzaMsg , fixture . componentInstance . viewContainerRef ) ;
5140
5241 flushMicrotasks ( ) ;
5342 } ) ) ) ;
@@ -140,24 +129,29 @@ describe('Overlay', () => {
140129
141130
142131/** Simple component for testing ComponentPortal. */
143- @Component ( {
144- selector : 'pizza-msg' ,
145- template : '<p>Pizza</p>' ,
146- } )
132+ @Component ( { template : '<p>Pizza</p>' } )
147133class PizzaMsg { }
148134
149135
150136/** Test-bed component that contains a TempatePortal and an ElementRef. */
151- @Component ( {
152- selector : 'portal-test' ,
153- template : `<template portal>Cake</template>` ,
154- } )
137+ @Component ( { template : `<template portal>Cake</template>` } )
155138class TestComponentWithTemplatePortals {
156139 @ViewChild ( TemplatePortalDirective ) templatePortal : TemplatePortalDirective ;
157140
158141 constructor ( public viewContainerRef : ViewContainerRef ) { }
159142}
160143
144+ // Create a real (non-test) NgModule as a workaround for
145+ // https://github.com/angular/angular/issues/10760
146+ const TEST_COMPONENTS = [ PizzaMsg , TestComponentWithTemplatePortals ] ;
147+ @NgModule ( {
148+ imports : [ OverlayModule , PortalModule ] ,
149+ exports : TEST_COMPONENTS ,
150+ declarations : TEST_COMPONENTS ,
151+ entryComponents : TEST_COMPONENTS ,
152+ } )
153+ class OverlayTestModule { }
154+
161155class FakePositionStrategy implements PositionStrategy {
162156 apply ( element : Element ) : Promise < void > {
163157 element . classList . add ( 'fake-positioned' ) ;
0 commit comments