From ef1a387baf5234337f6f53a465f15e03d03e744b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Remiszewski?= Date: Wed, 11 Oct 2023 13:30:15 +0200 Subject: [PATCH] Fix tests. --- src/ckeditor/ckeditor.component.spec.ts | 38 ++++++++++++++++--------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/ckeditor/ckeditor.component.spec.ts b/src/ckeditor/ckeditor.component.spec.ts index 25b36d0..ce5b8b3 100644 --- a/src/ckeditor/ckeditor.component.spec.ts +++ b/src/ckeditor/ckeditor.component.spec.ts @@ -491,27 +491,36 @@ describe( 'CKEditorComponent', () => { } ); } ); } ); + describe( 'initialization errors are catched', () => { - const CrashyEditor = AngularEditor; - let originalCreate: any; + let config: any; beforeEach( () => { - originalCreate = AngularEditor.create; - CrashyEditor.create = () => { - throw 'init failure'; + config = { + extraPlugins: [ + function( editor: any ) { + editor.data.on( 'init', () => { + // Simulate an error. + // Create a non-existing position, then try to get its parent. + const position = editor.model.createPositionFromPath( editor.model.document.getRoot(), [ 1, 2, 3 ] ); + + return position.parent; + } ); + } + ], + collaboration: { + channelId: 'foobar-baz' + } }; } ); - afterEach( () => { - AngularEditor.create = originalCreate; - } ); - - it( 'when internal watchgod is created', async () => { + it( 'when internal watchdog is created', async () => { fixture = TestBed.createComponent( CKEditorComponent ); + const component = fixture.componentInstance; const errorSpy = jasmine.createSpy( 'errorSpy' ); component.error.subscribe( errorSpy ); - component.editor = CrashyEditor; - component.ngAfterViewInit(); + component.editor = AngularEditor; + component.config = config; fixture.detectChanges(); await waitCycle(); @@ -523,6 +532,7 @@ describe( 'CKEditorComponent', () => { it( 'when external watchdog is provided', async () => { fixture = TestBed.createComponent( CKEditorComponent ); + const component = fixture.componentInstance; const errorSpy = jasmine.createSpy( 'errorSpy' ); component.error.subscribe( errorSpy ); const contextWatchdog = new AngularEditor.ContextWatchdog( AngularEditor.Context ); @@ -530,8 +540,8 @@ describe( 'CKEditorComponent', () => { await contextWatchdog.create(); component.watchdog = contextWatchdog; - component.editor = CrashyEditor; - component.ngAfterViewInit(); + component.editor = AngularEditor; + component.config = config; fixture.detectChanges(); await waitCycle();