@@ -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,11 +146,15 @@ 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 ( ) ;
@@ -361,27 +360,32 @@ function getChangesObj(oldProps: Record<string, any> | null, newProps: Record<st
361
360
) ;
362
361
}
363
362
364
- function updateProps < SutType > (
363
+ function update < SutType > (
365
364
fixture : ComponentFixture < SutType > ,
366
- prevRenderedPropsKeys : string [ ] ,
367
- 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 ,
368
371
) {
369
372
const componentInstance = fixture . componentInstance as Record < string , any > ;
370
373
const simpleChanges : SimpleChanges = { } ;
371
374
372
- for ( const key of prevRenderedPropsKeys ) {
373
- if ( ! Object . prototype . hasOwnProperty . call ( newProps , key ) ) {
375
+ for ( const key of prevRenderedKeys ) {
376
+ if ( ! Object . prototype . hasOwnProperty . call ( newValues , key ) ) {
374
377
simpleChanges [ key ] = new SimpleChange ( componentInstance [ key ] , undefined , false ) ;
375
378
delete componentInstance [ key ] ;
376
379
}
377
380
}
378
381
379
- for ( const [ key , value ] of Object . entries ( newProps ) ) {
382
+ for ( const [ key , value ] of Object . entries ( newValues ) ) {
380
383
if ( value !== componentInstance [ key ] ) {
381
384
simpleChanges [ key ] = new SimpleChange ( componentInstance [ key ] , value , false ) ;
382
385
}
383
386
}
384
- setComponentProperties ( fixture , newProps ) ;
387
+
388
+ updateFunction ( fixture , newValues ) ;
385
389
386
390
return simpleChanges ;
387
391
}
0 commit comments