Commit cbd5d09b authored by Paul Slaughter's avatar Paul Slaughter Committed by Enrique Alcantara

Fix dom shims to support rich_content_editor

- Remove mutation observer shim since
  this is an incomplete API
- Remove our custom Range support since
  this was already added by jsdom
- Extend the Range.prototype with missing
  methods
parent 2df781b0
...@@ -50,16 +50,6 @@ class CustomEnvironment extends JSDOMEnvironment { ...@@ -50,16 +50,6 @@ class CustomEnvironment extends JSDOMEnvironment {
*/ */
this.global.fetch = () => {}; this.global.fetch = () => {};
// Not yet supported by JSDOM: https://github.com/jsdom/jsdom/issues/317
this.global.document.createRange = () => ({
setStart: () => {},
setEnd: () => {},
commonAncestorContainer: {
nodeName: 'BODY',
ownerDocument: this.global.document,
},
});
// Expose the jsdom (created in super class) to the global so that we can call reconfigure({ url: '' }) to properly set `window.location` // Expose the jsdom (created in super class) to the global so that we can call reconfigure({ url: '' }) to properly set `window.location`
this.global.dom = this.dom; this.global.dom = this.dom;
} }
......
...@@ -4,7 +4,7 @@ import './element_scroll_to'; ...@@ -4,7 +4,7 @@ import './element_scroll_to';
import './form_element'; import './form_element';
import './get_client_rects'; import './get_client_rects';
import './inner_text'; import './inner_text';
import './mutation_observer'; import './range';
import './window_scroll_to'; import './window_scroll_to';
import './scroll_by'; import './scroll_by';
import './size_properties'; import './size_properties';
......
/* eslint-disable class-methods-use-this */
class MutationObserverStub {
disconnect() {}
observe() {}
}
global.MutationObserver = MutationObserverStub;
if (window.Range.prototype.getBoundingClientRect) {
throw new Error('window.Range.prototype.getBoundingClientRect already exists. Remove this stub!');
}
window.Range.prototype.getBoundingClientRect = function getBoundingClientRect() {
return { x: 0, y: 0, width: 0, height: 0, top: 0, right: 0, bottom: 0, left: 0 };
};
if (window.Range.prototype.getClientRects) {
throw new Error('window.Range.prototype.getClientRects already exists. Remove this stub!');
}
window.Range.prototype.getClientRects = function getClientRects() {
return [this.getBoundingClientRect()];
};
import Editor from '@toast-ui/editor'; import Editor from '@toast-ui/editor';
import { registerHTMLToMarkdownRenderer } from '~/vue_shared/components/rich_content_editor/services/editor_service'; import { registerHTMLToMarkdownRenderer } from '~/vue_shared/components/rich_content_editor/services/editor_service';
import '@toast-ui/editor/dist/toastui-editor.css';
describe('vue_shared/components/rich_content_editor', () => { describe('vue_shared/components/rich_content_editor', () => {
let editor; let editor;
...@@ -18,7 +17,6 @@ describe('vue_shared/components/rich_content_editor', () => { ...@@ -18,7 +17,6 @@ describe('vue_shared/components/rich_content_editor', () => {
}); });
describe('HTML to Markdown', () => { describe('HTML to Markdown', () => {
it('uses "-" character list marker in unordered lists', () => { it('uses "-" character list marker in unordered lists', () => {
editor.setHtml('<ul><li>List item 1</li><li>List item 2</li></ul>'); editor.setHtml('<ul><li>List item 1</li><li>List item 2</li></ul>');
......
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