Commit a677fbaf authored by Phil Hughes's avatar Phil Hughes

fixed up editor spec by catching any thrown errors

parent e64b93cc
...@@ -121,12 +121,20 @@ export default class Editor { ...@@ -121,12 +121,20 @@ export default class Editor {
} }
dispose() { dispose() {
this.disposable.dispose();
window.removeEventListener('resize', this.debouncedUpdate); window.removeEventListener('resize', this.debouncedUpdate);
// dispose main monaco instance try {
if (this.instance) { this.disposable.dispose();
this.instance = null;
// dispose main monaco instance
if (this.instance) {
this.instance = null;
}
} catch (e) {
// dispose main monaco instance
if (this.instance) {
this.instance = null;
}
} }
} }
......
...@@ -5,8 +5,16 @@ import { file } from '../helpers'; ...@@ -5,8 +5,16 @@ import { file } from '../helpers';
describe('Multi-file editor library', () => { describe('Multi-file editor library', () => {
let instance; let instance;
let el;
let holder;
beforeEach((done) => { beforeEach((done) => {
el = document.createElement('div');
holder = document.createElement('div');
el.appendChild(holder);
document.body.appendChild(el);
monacoLoader(['vs/editor/editor.main'], () => { monacoLoader(['vs/editor/editor.main'], () => {
instance = editor.create(monaco); instance = editor.create(monaco);
...@@ -16,6 +24,8 @@ describe('Multi-file editor library', () => { ...@@ -16,6 +24,8 @@ describe('Multi-file editor library', () => {
afterEach(() => { afterEach(() => {
instance.dispose(); instance.dispose();
el.remove();
}); });
it('creates instance of editor', () => { it('creates instance of editor', () => {
...@@ -27,46 +37,34 @@ describe('Multi-file editor library', () => { ...@@ -27,46 +37,34 @@ describe('Multi-file editor library', () => {
}); });
describe('createInstance', () => { describe('createInstance', () => {
let el;
beforeEach(() => {
el = document.createElement('div');
});
it('creates editor instance', () => { it('creates editor instance', () => {
spyOn(instance.monaco.editor, 'create').and.callThrough(); spyOn(instance.monaco.editor, 'create').and.callThrough();
instance.createInstance(el); instance.createInstance(holder);
expect(instance.monaco.editor.create).toHaveBeenCalled(); expect(instance.monaco.editor.create).toHaveBeenCalled();
}); });
it('creates dirty diff controller', () => { it('creates dirty diff controller', () => {
instance.createInstance(el); instance.createInstance(holder);
expect(instance.dirtyDiffController).not.toBeNull(); expect(instance.dirtyDiffController).not.toBeNull();
}); });
it('creates model manager', () => { it('creates model manager', () => {
instance.createInstance(el); instance.createInstance(holder);
expect(instance.modelManager).not.toBeNull(); expect(instance.modelManager).not.toBeNull();
}); });
}); });
describe('createDiffInstance', () => { describe('createDiffInstance', () => {
let el;
beforeEach(() => {
el = document.createElement('div');
});
it('creates editor instance', () => { it('creates editor instance', () => {
spyOn(instance.monaco.editor, 'createDiffEditor').and.callThrough(); spyOn(instance.monaco.editor, 'createDiffEditor').and.callThrough();
instance.createDiffInstance(el); instance.createDiffInstance(holder);
expect(instance.monaco.editor.createDiffEditor).toHaveBeenCalledWith(el, { expect(instance.monaco.editor.createDiffEditor).toHaveBeenCalledWith(holder, {
readOnly: true, readOnly: true,
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment