77 SimpleChanges ,
88 APP_INITIALIZER ,
99 ApplicationInitStatus ,
10+ Injectable ,
1011} from '@angular/core' ;
1112import { NoopAnimationsModule , BrowserAnimationsModule } from '@angular/platform-browser/animations' ;
1213import { TestBed } from '@angular/core/testing' ;
@@ -19,7 +20,7 @@ import { render, fireEvent, screen } from '../src/public_api';
1920 <button>button</button>
2021 ` ,
2122} )
22- class FixtureComponent { }
23+ class FixtureComponent { }
2324
2425test ( 'creates queries and events' , async ( ) => {
2526 const view = await render ( FixtureComponent ) ;
@@ -50,46 +51,84 @@ describe('standalone', () => {
5051
5152describe ( 'standalone with child' , ( ) => {
5253 @Component ( {
53- selector : 'child-fixture' ,
54+ selector : 'atl- child-fixture' ,
5455 template : `<span>A child fixture</span>` ,
5556 standalone : true ,
5657 } )
57- class ChildFixture { }
58+ class ChildFixtureComponent { }
5859
5960 @Component ( {
60- selector : 'child-fixture' ,
61+ selector : 'atl- child-fixture' ,
6162 template : `<span>A mock child fixture</span>` ,
6263 standalone : true ,
6364 } )
64- class MockChildFixture { }
65+ class MockChildFixtureComponent { }
6566
6667 @Component ( {
67- selector : 'parent-fixture' ,
68+ selector : 'atl- parent-fixture' ,
6869 template : `<h1>Parent fixture</h1>
69- <div><child-fixture></child-fixture></div> ` ,
70+ <div><atl- child-fixture></atl- child-fixture></div> ` ,
7071 standalone : true ,
71- imports : [ ChildFixture ] ,
72+ imports : [ ChildFixtureComponent ] ,
7273 } )
73- class ParentFixture { }
74+ class ParentFixtureComponent { }
7475
7576 it ( 'renders the standalone component with child' , async ( ) => {
76- await render ( ParentFixture ) ;
77- expect ( screen . getByText ( 'Parent fixture' ) ) ;
78- expect ( screen . getByText ( 'A child fixture' ) ) ;
77+ await render ( ParentFixtureComponent ) ;
78+ expect ( screen . getByText ( 'Parent fixture' ) ) . toBeInTheDocument ( ) ;
79+ expect ( screen . getByText ( 'A child fixture' ) ) . toBeInTheDocument ( ) ;
7980 } ) ;
8081
81- it ( 'renders the standalone component with child' , async ( ) => {
82- await render ( ParentFixture , { ɵcomponentImports : [ MockChildFixture ] } ) ;
83- expect ( screen . getByText ( 'Parent fixture' ) ) ;
84- expect ( screen . getByText ( 'A mock child fixture' ) ) ;
82+ it ( 'renders the standalone component with child given ɵcomponentImports ' , async ( ) => {
83+ await render ( ParentFixtureComponent , { ɵcomponentImports : [ MockChildFixtureComponent ] } ) ;
84+ expect ( screen . getByText ( 'Parent fixture' ) ) . toBeInTheDocument ( ) ;
85+ expect ( screen . getByText ( 'A mock child fixture' ) ) . toBeInTheDocument ( ) ;
8586 } ) ;
8687
8788 it ( 'rejects render of template with componentImports set' , ( ) => {
88- const result = render ( `<div><parent-fixture></parent-fixture></div>` , {
89- imports : [ ParentFixture ] ,
90- ɵcomponentImports : [ MockChildFixture ] ,
89+ const view = render ( `<div><atl-parent-fixture></atl-parent-fixture></div>` , {
90+ imports : [ ParentFixtureComponent ] ,
91+ ɵcomponentImports : [ MockChildFixtureComponent ] ,
92+ } ) ;
93+ return expect ( view ) . rejects . toMatchObject ( { message : / E r r o r w h i l e r e n d e r i n g / } ) ;
94+ } ) ;
95+ } ) ;
96+
97+ describe ( 'childComponentOverrides' , ( ) => {
98+ @Injectable ( )
99+ class MySimpleService {
100+ public value = 'real' ;
101+ }
102+
103+ @Component ( {
104+ selector : 'atl-child-fixture' ,
105+ template : `<span>{{ simpleService.value }}</span>` ,
106+ standalone : true ,
107+ providers : [ MySimpleService ] ,
108+ } )
109+ class NestedChildFixtureComponent {
110+ public constructor ( public simpleService : MySimpleService ) { }
111+ }
112+
113+ @Component ( {
114+ selector : 'atl-parent-fixture' ,
115+ template : `<atl-child-fixture></atl-child-fixture>` ,
116+ standalone : true ,
117+ imports : [ NestedChildFixtureComponent ] ,
118+ } )
119+ class ParentFixtureComponent { }
120+
121+ it ( 'renders with overridden child service when specified' , async ( ) => {
122+ await render ( ParentFixtureComponent , {
123+ childComponentOverrides : [
124+ {
125+ component : NestedChildFixtureComponent ,
126+ providers : [ { provide : MySimpleService , useValue : { value : 'fake' } } ] ,
127+ } ,
128+ ] ,
91129 } ) ;
92- return expect ( result ) . rejects . toMatchObject ( { message : / E r r o r w h i l e r e n d e r i n g / } ) ;
130+
131+ expect ( screen . getByText ( 'fake' ) ) . toBeInTheDocument ( ) ;
93132 } ) ;
94133} ) ;
95134
@@ -117,7 +156,7 @@ describe('animationModule', () => {
117156 @NgModule ( {
118157 declarations : [ FixtureComponent ] ,
119158 } )
120- class FixtureModule { }
159+ class FixtureModule { }
121160 describe ( 'excludeComponentDeclaration' , ( ) => {
122161 it ( 'does not throw if component is declared in an imported module' , async ( ) => {
123162 await render ( FixtureComponent , {
0 commit comments