diff --git a/src/ckeditor/ckeditor.component.spec.ts b/src/ckeditor/ckeditor.component.spec.ts index 2bc0210..f30fc40 100644 --- a/src/ckeditor/ckeditor.component.spec.ts +++ b/src/ckeditor/ckeditor.component.spec.ts @@ -188,6 +188,24 @@ describe( 'CKEditorComponent', () => { } ); } ); + it( 'change - should not calculate editor data when the control value ancestor is not specified', () => { + fixture.detectChanges(); + + const changeSpy = jasmine.createSpy(); + component.change.subscribe( changeSpy ); + + return wait().then( () => { + spyOn( component.editorInstance!, 'getData' ).and.callThrough(); + + component.editorInstance!.execute( 'input', { text: 'foo' } ); + component.editorInstance!.execute( 'input', { text: 'foo' } ); + component.editorInstance!.execute( 'input', { text: 'foo' } ); + + expect( component.editorInstance!.getData ).toHaveBeenCalledTimes( 0 ); + expect( changeSpy ).toHaveBeenCalledTimes( 3 ); + } ); + } ); + it( 'focus', () => { fixture.detectChanges(); const spy = jasmine.createSpy(); @@ -235,7 +253,7 @@ describe( 'CKEditorComponent', () => { } ); } ); - it( 'onChange callback should be called when editor model changes', () => { + it( 'onChange callback should be called when editor model changes with editor data', () => { fixture.detectChanges(); return wait().then( () => { @@ -244,7 +262,7 @@ describe( 'CKEditorComponent', () => { component.editorInstance!.execute( 'input', { text: 'foo' } ); - expect( spy ).toHaveBeenCalled(); + expect( spy ).toHaveBeenCalledWith( '
foo
' ); } ); } ); } ); diff --git a/src/ckeditor/ckeditor.component.ts b/src/ckeditor/ckeditor.component.ts index f8aa1f9..37598ab 100644 --- a/src/ckeditor/ckeditor.component.ts +++ b/src/ckeditor/ckeditor.component.ts @@ -256,10 +256,10 @@ export class CKEditorComponent implements AfterViewInit, OnDestroy, ControlValue const viewDocument = editor.editing.view.document; modelDocument.on( 'change:data', ( evt: CKEditor5.EventInfo<'change:data'> ) => { - const data = editor.getData(); - this.ngZone.run( () => { if ( this.cvaOnChange ) { + const data = editor.getData(); + this.cvaOnChange( data ); }