7
7
SimpleChanges ,
8
8
APP_INITIALIZER ,
9
9
ApplicationInitStatus ,
10
+ Injectable ,
10
11
} from '@angular/core' ;
11
12
import { NoopAnimationsModule , BrowserAnimationsModule } from '@angular/platform-browser/animations' ;
12
13
import { TestBed } from '@angular/core/testing' ;
@@ -19,7 +20,7 @@ import { render, fireEvent, screen } from '../src/public_api';
19
20
<button>button</button>
20
21
` ,
21
22
} )
22
- class FixtureComponent { }
23
+ class FixtureComponent { }
23
24
24
25
test ( 'creates queries and events' , async ( ) => {
25
26
const view = await render ( FixtureComponent ) ;
@@ -50,46 +51,84 @@ describe('standalone', () => {
50
51
51
52
describe ( 'standalone with child' , ( ) => {
52
53
@Component ( {
53
- selector : 'child-fixture' ,
54
+ selector : 'atl- child-fixture' ,
54
55
template : `<span>A child fixture</span>` ,
55
56
standalone : true ,
56
57
} )
57
- class ChildFixture { }
58
+ class ChildFixtureComponent { }
58
59
59
60
@Component ( {
60
- selector : 'child-fixture' ,
61
+ selector : 'atl- child-fixture' ,
61
62
template : `<span>A mock child fixture</span>` ,
62
63
standalone : true ,
63
64
} )
64
- class MockChildFixture { }
65
+ class MockChildFixtureComponent { }
65
66
66
67
@Component ( {
67
- selector : 'parent-fixture' ,
68
+ selector : 'atl- parent-fixture' ,
68
69
template : `<h1>Parent fixture</h1>
69
- <div><child-fixture></child-fixture></div> ` ,
70
+ <div><atl- child-fixture></atl- child-fixture></div> ` ,
70
71
standalone : true ,
71
- imports : [ ChildFixture ] ,
72
+ imports : [ ChildFixtureComponent ] ,
72
73
} )
73
- class ParentFixture { }
74
+ class ParentFixtureComponent { }
74
75
75
76
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 ( ) ;
79
80
} ) ;
80
81
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 ( ) ;
85
86
} ) ;
86
87
87
88
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
+ ] ,
91
129
} ) ;
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 ( ) ;
93
132
} ) ;
94
133
} ) ;
95
134
@@ -117,7 +156,7 @@ describe('animationModule', () => {
117
156
@NgModule ( {
118
157
declarations : [ FixtureComponent ] ,
119
158
} )
120
- class FixtureModule { }
159
+ class FixtureModule { }
121
160
describe ( 'excludeComponentDeclaration' , ( ) => {
122
161
it ( 'does not throw if component is declared in an imported module' , async ( ) => {
123
162
await render ( FixtureComponent , {
0 commit comments