@@ -133,12 +133,7 @@ export async function render<SutType, WrapperType = SutType>(
133
133
> ,
134
134
) => {
135
135
const newComponentInputs = properties ?. componentInputs ?? { } ;
136
- for ( const inputKey of renderedInputKeys ) {
137
- if ( ! Object . prototype . hasOwnProperty . call ( newComponentInputs , inputKey ) ) {
138
- delete ( fixture . componentInstance as any ) [ inputKey ] ;
139
- }
140
- }
141
- setComponentInputs ( fixture , newComponentInputs ) ;
136
+ const changesInComponentInput = update ( fixture , renderedInputKeys , newComponentInputs , setComponentInputs ) ;
142
137
renderedInputKeys = Object . keys ( newComponentInputs ) ;
143
138
144
139
const newComponentOutputs = properties ?. componentOutputs ?? { } ;
@@ -151,43 +146,21 @@ export async function render<SutType, WrapperType = SutType>(
151
146
renderedOutputKeys = Object . keys ( newComponentOutputs ) ;
152
147
153
148
const newComponentProps = properties ?. componentProperties ?? { } ;
154
- const changes = updateProps ( fixture , renderedPropKeys , newComponentProps ) ;
149
+ const changesInComponentProps = update ( fixture , renderedPropKeys , newComponentProps , setComponentProperties ) ;
150
+ renderedPropKeys = Object . keys ( newComponentProps ) ;
151
+
155
152
if ( hasOnChangesHook ( fixture . componentInstance ) ) {
156
- fixture . componentInstance . ngOnChanges ( changes ) ;
153
+ fixture . componentInstance . ngOnChanges ( {
154
+ ...changesInComponentInput ,
155
+ ...changesInComponentProps ,
156
+ } ) ;
157
157
}
158
- renderedPropKeys = Object . keys ( newComponentProps ) ;
159
158
160
159
if ( properties ?. detectChangesOnRender !== false ) {
161
160
fixture . componentRef . injector . get ( ChangeDetectorRef ) . detectChanges ( ) ;
162
161
}
163
162
} ;
164
163
165
- const changeInput = ( changedInputProperties : Partial < SutType > ) => {
166
- if ( Object . keys ( changedInputProperties ) . length === 0 ) {
167
- return ;
168
- }
169
-
170
- setComponentInputs ( fixture , changedInputProperties ) ;
171
-
172
- fixture . detectChanges ( ) ;
173
- } ;
174
-
175
- const change = ( changedProperties : Partial < SutType > ) => {
176
- if ( Object . keys ( changedProperties ) . length === 0 ) {
177
- return ;
178
- }
179
-
180
- const changes = getChangesObj ( fixture . componentInstance as Record < string , any > , changedProperties ) ;
181
-
182
- setComponentProperties ( fixture , changedProperties ) ;
183
-
184
- if ( hasOnChangesHook ( fixture . componentInstance ) ) {
185
- fixture . componentInstance . ngOnChanges ( changes ) ;
186
- }
187
-
188
- fixture . componentRef . injector . get ( ChangeDetectorRef ) . detectChanges ( ) ;
189
- } ;
190
-
191
164
const navigate = async ( elementOrPath : Element | string , basePath = '' ) : Promise < boolean > => {
192
165
const href = typeof elementOrPath === 'string' ? elementOrPath : elementOrPath . getAttribute ( 'href' ) ;
193
166
const [ path , params ] = ( basePath + href ) . split ( '?' ) ;
@@ -234,8 +207,6 @@ export async function render<SutType, WrapperType = SutType>(
234
207
detectChanges : ( ) => detectChanges ( ) ,
235
208
navigate,
236
209
rerender,
237
- change,
238
- changeInput,
239
210
// @ts -ignore: fixture assigned
240
211
debugElement : fixture . debugElement ,
241
212
// @ts -ignore: fixture assigned
@@ -389,27 +360,32 @@ function getChangesObj(oldProps: Record<string, any> | null, newProps: Record<st
389
360
) ;
390
361
}
391
362
392
- function updateProps < SutType > (
363
+ function update < SutType > (
393
364
fixture : ComponentFixture < SutType > ,
394
- prevRenderedPropsKeys : string [ ] ,
395
- newProps : Record < string , any > ,
365
+ prevRenderedKeys : string [ ] ,
366
+ newValues : Record < string , any > ,
367
+ updateFunction : (
368
+ fixture : ComponentFixture < SutType > ,
369
+ values : RenderTemplateOptions < SutType > [ 'componentInputs' | 'componentProperties' ] ,
370
+ ) => void ,
396
371
) {
397
372
const componentInstance = fixture . componentInstance as Record < string , any > ;
398
373
const simpleChanges : SimpleChanges = { } ;
399
374
400
- for ( const key of prevRenderedPropsKeys ) {
401
- if ( ! Object . prototype . hasOwnProperty . call ( newProps , key ) ) {
375
+ for ( const key of prevRenderedKeys ) {
376
+ if ( ! Object . prototype . hasOwnProperty . call ( newValues , key ) ) {
402
377
simpleChanges [ key ] = new SimpleChange ( componentInstance [ key ] , undefined , false ) ;
403
378
delete componentInstance [ key ] ;
404
379
}
405
380
}
406
381
407
- for ( const [ key , value ] of Object . entries ( newProps ) ) {
382
+ for ( const [ key , value ] of Object . entries ( newValues ) ) {
408
383
if ( value !== componentInstance [ key ] ) {
409
384
simpleChanges [ key ] = new SimpleChange ( componentInstance [ key ] , value , false ) ;
410
385
}
411
386
}
412
- setComponentProperties ( fixture , newProps ) ;
387
+
388
+ updateFunction ( fixture , newValues ) ;
413
389
414
390
return simpleChanges ;
415
391
}
0 commit comments