Commit 89108e00 authored by Enrique Alcántara's avatar Enrique Alcántara

Merge branch 'dmishunov/se-event-dispatch' into 'master'

Correctly pass instance in EDITOR_READY_EVENT

See merge request gitlab-org/gitlab!77852
parents c3eeefff 6be7d6be
......@@ -149,7 +149,7 @@ export default class SourceEditor {
});
this.instances.push(instance);
el.dispatchEvent(new CustomEvent(EDITOR_READY_EVENT, { instance }));
el.dispatchEvent(new CustomEvent(EDITOR_READY_EVENT, { detail: { instance } }));
return instance;
}
......
......@@ -342,27 +342,30 @@ describe('Base editor', () => {
describe('implementation', () => {
let instance;
beforeEach(() => {
instance = editor.createInstance({ el: editorEl, blobPath, blobContent });
});
it('correctly proxies value from the model', () => {
instance = editor.createInstance({ el: editorEl, blobPath, blobContent });
expect(instance.getValue()).toBe(blobContent);
});
it('emits the EDITOR_READY_EVENT event after setting up the instance', () => {
it('emits the EDITOR_READY_EVENT event passing the instance after setting it up', () => {
jest.spyOn(monacoEditor, 'create').mockImplementation(() => {
return {
setModel: jest.fn(),
onDidDispose: jest.fn(),
layout: jest.fn(),
dispose: jest.fn(),
};
});
const eventSpy = jest.fn();
let passedInstance;
const eventSpy = jest.fn().mockImplementation((ev) => {
passedInstance = ev.detail.instance;
});
editorEl.addEventListener(EDITOR_READY_EVENT, eventSpy);
expect(eventSpy).not.toHaveBeenCalled();
editor.createInstance({ el: editorEl });
instance = editor.createInstance({ el: editorEl });
expect(eventSpy).toHaveBeenCalled();
expect(passedInstance).toBe(instance);
});
});
......
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