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