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 { ...@@ -149,7 +149,7 @@ export default class SourceEditor {
}); });
this.instances.push(instance); this.instances.push(instance);
el.dispatchEvent(new CustomEvent(EDITOR_READY_EVENT, { instance })); el.dispatchEvent(new CustomEvent(EDITOR_READY_EVENT, { detail: { instance } }));
return instance; return instance;
} }
......
...@@ -342,27 +342,30 @@ describe('Base editor', () => { ...@@ -342,27 +342,30 @@ describe('Base editor', () => {
describe('implementation', () => { describe('implementation', () => {
let instance; let instance;
beforeEach(() => {
instance = editor.createInstance({ el: editorEl, blobPath, blobContent });
});
it('correctly proxies value from the model', () => { it('correctly proxies value from the model', () => {
instance = editor.createInstance({ el: editorEl, blobPath, blobContent });
expect(instance.getValue()).toBe(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(() => { jest.spyOn(monacoEditor, 'create').mockImplementation(() => {
return { return {
setModel: jest.fn(), setModel: jest.fn(),
onDidDispose: jest.fn(), onDidDispose: jest.fn(),
layout: 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); editorEl.addEventListener(EDITOR_READY_EVENT, eventSpy);
expect(eventSpy).not.toHaveBeenCalled(); expect(eventSpy).not.toHaveBeenCalled();
editor.createInstance({ el: editorEl }); instance = editor.createInstance({ el: editorEl });
expect(eventSpy).toHaveBeenCalled(); 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