@@ -8,6 +8,7 @@ import { ButtonOutputComponent } from "./components/button-output.component";
8
8
import { createOutputSpy } from 'cypress/angular' ;
9
9
import { EventEmitter , Component } from '@angular/core' ;
10
10
import { ProjectionComponent } from "./components/projection.component" ;
11
+ import { LifecycleComponent } from "./components/lifecycle.component" ;
11
12
12
13
@Component ( {
13
14
template : `<app-projection>Hello World</app-projection>`
@@ -164,7 +165,60 @@ describe("angular mount", () => {
164
165
} )
165
166
cy . get ( 'h3' ) . contains ( 'Hello World' )
166
167
} )
168
+
169
+ it ( 'handles ngOnChanges on mount' , ( ) => {
170
+ cy . mount ( LifecycleComponent , {
171
+ componentProperties : {
172
+ name : 'Angular'
173
+ }
174
+ } )
175
+
176
+ cy . get ( 'p' ) . should ( 'have.text' , 'Hi Angular. ngOnInit fired: true and ngOnChanges fired: true and conditionalName: false' )
177
+ } )
178
+
179
+ it ( 'handles ngOnChanges on mount with templates' , ( ) => {
180
+ cy . mount ( '<app-lifecycle [name]="name"></app-lifecycle>' , {
181
+ declarations : [ LifecycleComponent ] ,
182
+ componentProperties : {
183
+ name : 'Angular'
184
+ }
185
+ } )
186
+
187
+ cy . get ( 'p' ) . should ( 'have.text' , 'Hi Angular. ngOnInit fired: true and ngOnChanges fired: true and conditionalName: false' )
188
+ } )
167
189
190
+ it ( 'creates simpleChanges from componentProperties and calls ngOnChanges on Mount' , ( ) => {
191
+ cy . mount ( LifecycleComponent , {
192
+ componentProperties : {
193
+ name : 'CONDITIONAL NAME'
194
+ }
195
+ } )
196
+ cy . get ( 'p' ) . should ( 'have.text' , 'Hi CONDITIONAL NAME. ngOnInit fired: true and ngOnChanges fired: true and conditionalName: true' )
197
+ } )
198
+
199
+ it ( 'creates simpleChanges from componentProperties and calls ngOnChanges on Mount with template' , ( ) => {
200
+ cy . mount ( '<app-lifecycle [name]="name"></app-lifecycle>' , {
201
+ declarations : [ LifecycleComponent ] ,
202
+ componentProperties : {
203
+ name : 'CONDITIONAL NAME'
204
+ }
205
+ } )
206
+ cy . get ( 'p' ) . should ( 'have.text' , 'Hi CONDITIONAL NAME. ngOnInit fired: true and ngOnChanges fired: true and conditionalName: true' )
207
+ } )
208
+
209
+ it ( 'ngOnChanges is not fired when no componentProperties given' , ( ) => {
210
+ cy . mount ( LifecycleComponent )
211
+ cy . get ( 'p' ) . should ( 'have.text' , 'Hi . ngOnInit fired: true and ngOnChanges fired: false and conditionalName: false' )
212
+ } )
213
+
214
+ it ( 'ngOnChanges is not fired when no componentProperties given with template' , ( ) => {
215
+ cy . mount ( '<app-lifecycle></app-lifecycle>' , {
216
+ declarations : [ LifecycleComponent ]
217
+ } )
218
+ cy . get ( 'p' ) . should ( 'have.text' , 'Hi . ngOnInit fired: true and ngOnChanges fired: false and conditionalName: false' )
219
+ } )
220
+
221
+
168
222
describe ( "teardown" , ( ) => {
169
223
beforeEach ( ( ) => {
170
224
cy . get ( "[id^=root]" ) . should ( "not.exist" ) ;
0 commit comments