@@ -120,14 +120,38 @@ export async function render<SutType, WrapperType = SutType>(
120
120
121
121
await renderFixture ( componentProperties , componentInputs , componentOutputs ) ;
122
122
123
+ let renderedPropKeys = Object . keys ( componentProperties ) ;
124
+ let renderedInputKeys = Object . keys ( componentInputs ) ;
125
+ let renderedOutputKeys = Object . keys ( componentOutputs ) ;
123
126
const rerender = async (
124
127
properties ?: Pick < RenderTemplateOptions < SutType > , 'componentProperties' | 'componentInputs' | 'componentOutputs' > ,
125
128
) => {
126
- await renderFixture (
127
- properties ?. componentProperties ?? { } ,
128
- properties ?. componentInputs ?? { } ,
129
- properties ?. componentOutputs ?? { } ,
130
- ) ;
129
+ const newComponentInputs = properties ?. componentInputs ?? { } ;
130
+ for ( const inputKey of renderedInputKeys ) {
131
+ if ( ! Object . prototype . hasOwnProperty . call ( newComponentInputs , inputKey ) ) {
132
+ delete ( fixture . componentInstance as any ) [ inputKey ] ;
133
+ }
134
+ }
135
+ setComponentInputs ( fixture , newComponentInputs ) ;
136
+ renderedInputKeys = Object . keys ( newComponentInputs ) ;
137
+
138
+ const newComponentOutputs = properties ?. componentOutputs ?? { } ;
139
+ for ( const outputKey of renderedOutputKeys ) {
140
+ if ( ! Object . prototype . hasOwnProperty . call ( newComponentOutputs , outputKey ) ) {
141
+ delete ( fixture . componentInstance as any ) [ outputKey ] ;
142
+ }
143
+ }
144
+ setComponentOutputs ( fixture , newComponentOutputs ) ;
145
+ renderedOutputKeys = Object . keys ( newComponentOutputs ) ;
146
+
147
+ const newComponentProps = properties ?. componentProperties ?? { } ;
148
+ const changes = updateProps ( fixture , renderedPropKeys , newComponentProps ) ;
149
+ if ( hasOnChangesHook ( fixture . componentInstance ) ) {
150
+ fixture . componentInstance . ngOnChanges ( changes ) ;
151
+ }
152
+ renderedPropKeys = Object . keys ( newComponentProps ) ;
153
+
154
+ fixture . componentRef . injector . get ( ChangeDetectorRef ) . detectChanges ( ) ;
131
155
} ;
132
156
133
157
const changeInput = ( changedInputProperties : Partial < SutType > ) => {
@@ -357,6 +381,31 @@ function getChangesObj(oldProps: Record<string, any> | null, newProps: Record<st
357
381
) ;
358
382
}
359
383
384
+ function updateProps < SutType > (
385
+ fixture : ComponentFixture < SutType > ,
386
+ prevRenderedPropsKeys : string [ ] ,
387
+ newProps : Record < string , any > ,
388
+ ) {
389
+ const componentInstance = fixture . componentInstance as Record < string , any > ;
390
+ const simpleChanges : SimpleChanges = { } ;
391
+
392
+ for ( const key of prevRenderedPropsKeys ) {
393
+ if ( ! Object . prototype . hasOwnProperty . call ( newProps , key ) ) {
394
+ simpleChanges [ key ] = new SimpleChange ( componentInstance [ key ] , undefined , false ) ;
395
+ delete componentInstance [ key ] ;
396
+ }
397
+ }
398
+
399
+ for ( const [ key , value ] of Object . entries ( newProps ) ) {
400
+ if ( value !== componentInstance [ key ] ) {
401
+ simpleChanges [ key ] = new SimpleChange ( componentInstance [ key ] , value , false ) ;
402
+ }
403
+ }
404
+ setComponentProperties ( fixture , newProps ) ;
405
+
406
+ return simpleChanges ;
407
+ }
408
+
360
409
function addAutoDeclarations < SutType > (
361
410
sut : Type < SutType > | string ,
362
411
{
0 commit comments