Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mremiszewski committed Oct 11, 2023
1 parent 3b23945 commit ef1a387
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions src/ckeditor/ckeditor.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -523,15 +532,16 @@ 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 );

await contextWatchdog.create();

component.watchdog = contextWatchdog;
component.editor = CrashyEditor;
component.ngAfterViewInit();
component.editor = AngularEditor;
component.config = config;

fixture.detectChanges();
await waitCycle();
Expand Down

0 comments on commit ef1a387

Please sign in to comment.