diff --git a/src/editor/index.ts b/src/editor/index.ts index 465c0b53c..9786c46e7 100644 --- a/src/editor/index.ts +++ b/src/editor/index.ts @@ -10,7 +10,7 @@ import SelectionAndRangeAPI from './selection' import CommandAPI from './command' import Text from '../text/index' import Menus from '../menus/index' -import initDom from './init-fns/init-dom' +import initDom, { selectorValidator } from './init-fns/init-dom' import initSelection from './init-fns/init-selection' import bindEvent from './init-fns/bind-event' import i18nextInit from './init-fns/i18next-init' @@ -87,9 +87,7 @@ class Editor { this.toolbarSelector = toolbarSelector this.textSelector = textSelector - if (toolbarSelector == null) { - throw new Error('错误:初始化编辑器时候未传入任何参数,请查阅文档') - } + selectorValidator(this) // 属性的默认值,后面可能会再修改 // 默认配置 - 当一个页面有多个编辑器的时候,因为 JS 的特性(引用类型)会导致多个编辑器的 config 引用是同一个,所以需要 深度克隆 断掉引用 diff --git a/src/editor/init-fns/init-dom.ts b/src/editor/init-fns/init-dom.ts index 9cf42f228..f0688a436 100644 --- a/src/editor/init-fns/init-dom.ts +++ b/src/editor/init-fns/init-dom.ts @@ -111,3 +111,49 @@ export default function (editor: Editor): void { editor.toolbarElemId = toolbarElemId editor.textElemId = textElemId } + +/** + * 工具栏/文本区域 DOM selector 有效性验证 + * @param editor 编辑器实例 + */ +export function selectorValidator(editor: Editor) { + const name = 'data-we-id' + const regexp = /^wangEditor-\d+$/ + const { textSelector, toolbarSelector } = editor + + const $el = { + bar: $('
'), + text: $('
'), + } + + if (toolbarSelector == null) { + throw new Error('错误:初始化编辑器时候未传入任何参数,请查阅文档') + } else { + $el.bar = $(toolbarSelector) + if (!$el.bar.elems.length) { + throw new Error(`无效的节点选择器:${toolbarSelector}`) + } + if (regexp.test($el.bar.attr(name))) { + throw new Error('初始化节点已存在编辑器实例,无法重复创建编辑器') + } + } + if (textSelector) { + $el.text = $(textSelector) + if (!$el.text.elems.length) { + throw new Error(`无效的节点选择器:${textSelector}`) + } + if (regexp.test($el.text.attr(name))) { + throw new Error('初始化节点已存在编辑器实例,无法重复创建编辑器') + } + } + + // 给节点做上标记 + $el.bar.attr(name, editor.id) + $el.text.attr(name, editor.id) + + // 在编辑器销毁前取消标记 + editor.beforeDestroy(function () { + $el.bar.removeAttr(name) + $el.text.removeAttr(name) + }) +} diff --git a/test/helpers/create-editor.ts b/test/helpers/create-editor.ts index bfad7b0bb..835ab8dcf 100644 --- a/test/helpers/create-editor.ts +++ b/test/helpers/create-editor.ts @@ -6,13 +6,22 @@ import Editor from '../../src/editor/index' import $ from 'jquery' +let count = 1 + +/** + * 生成唯一的节点 id + */ +export function selector() { + return `edit${count++}` +} + /** * 创建编辑器实例,用于测试 * @param document document * @param toolbarId toolbar id * @param textId text id */ -function createEditor( +export default function createEditor( document: Document, toolbarId: string, textId?: string, @@ -48,5 +57,3 @@ function createEditor( editor.create() return editor } - -export default createEditor diff --git a/test/unit/config/menus.test.ts b/test/unit/config/menus.test.ts index 58196a090..ed4610c80 100644 --- a/test/unit/config/menus.test.ts +++ b/test/unit/config/menus.test.ts @@ -3,10 +3,10 @@ * @author wangfupeng */ -import createEditor from '../../helpers/create-editor' +import createEditor, { selector } from '../../helpers/create-editor' test('菜单数量', () => { - const editor = createEditor(document, 'div1') + const editor = createEditor(document, selector()) const menus = editor.config.menus const $toolbarChildren = editor.$toolbarElem.childNodes() || [] let childrenLen = $toolbarChildren.length - 1 @@ -17,7 +17,7 @@ test('菜单数量', () => { // 各个菜单的配置,随后开发的时候再加 test('菜单 exclude', () => { - const editor = createEditor(document, 'div1', '', { + const editor = createEditor(document, selector(), '', { excludeMenus: ['bold'], }) const menus = editor.config.menus diff --git a/test/unit/editor/auto-focus.test.ts b/test/unit/editor/auto-focus.test.ts index 371282eb3..5a9eeff4b 100644 --- a/test/unit/editor/auto-focus.test.ts +++ b/test/unit/editor/auto-focus.test.ts @@ -3,7 +3,7 @@ * @author tonghan */ -import createEditor from '../../helpers/create-editor' +import createEditor, { selector } from '../../helpers/create-editor' import $ from '../../../src/utils/dom-core' const TEXT = '我是一行文字' @@ -12,13 +12,13 @@ const $P = $('

') $P.append($SPAN) test('auto-focus: false', () => { - createEditor(document, 'div1', '', { focus: false }) + createEditor(document, selector(), '', { focus: false }) const rangeCount = window?.getSelection()?.rangeCount expect(rangeCount).toBe(0) }) test('auto-focus: true', () => { - createEditor(document, 'div1') + createEditor(document, selector()) const rangeCount = window?.getSelection()?.rangeCount expect(rangeCount).toBe(1) }) diff --git a/test/unit/editor/disable.test.ts b/test/unit/editor/disable.test.ts index fe936926e..3f54fa956 100644 --- a/test/unit/editor/disable.test.ts +++ b/test/unit/editor/disable.test.ts @@ -1,4 +1,4 @@ -import createEditor from '../../helpers/create-editor' +import createEditor, { selector } from '../../helpers/create-editor' import Editor from '../../../src/editor/index' import disableInit from '../../../src/editor/disable' @@ -6,7 +6,7 @@ let editor: Editor describe('Editor disable', () => { beforeEach(() => { - editor = createEditor(document, 'div1') + editor = createEditor(document, selector()) }) test('编辑器可以被禁用', () => { diff --git a/test/unit/editor/full-screen-config.test.ts b/test/unit/editor/full-screen-config.test.ts new file mode 100644 index 000000000..f5a08fc3b --- /dev/null +++ b/test/unit/editor/full-screen-config.test.ts @@ -0,0 +1,35 @@ +import createEditor, { selector } from '../../helpers/create-editor' +import Editor from '../../../src/editor/index' +import $ from 'jquery' + +let editor: Editor +const FULLSCREEN_MENU_CLASS_SELECTOR = '.w-e-icon-fullscreen' + +describe('设置全屏', () => { + beforeEach(() => { + editor = createEditor(document, selector()) + }) + + test('编辑器默认初始化全屏菜单', () => { + const toolbarSelector = editor.$toolbarElem.elems[0].className + const fullMenuEl = $(`.${toolbarSelector}`).find(FULLSCREEN_MENU_CLASS_SELECTOR) + + expect(fullMenuEl.length).toBe(1) + }) + + test('编辑器区和菜单分离的编辑器不初始化全屏菜单', () => { + const seprateModeEditor = createEditor(document, selector(), selector()) + const toolbarSelector = seprateModeEditor.$toolbarElem.selector as string + const fullMenuEl = $(toolbarSelector).find(FULLSCREEN_MENU_CLASS_SELECTOR) + + expect(fullMenuEl.length).toBe(0) + }) + + test('编辑器配置 showFullScreen 为false时不初始化全屏菜单', () => { + const seprateModeEditor = createEditor(document, selector(), '', { showFullScreen: false }) + const toolbarSelector = seprateModeEditor.$toolbarElem.selector as string + const fullMenuEl = $(toolbarSelector).find(FULLSCREEN_MENU_CLASS_SELECTOR) + + expect(fullMenuEl.length).toBe(0) + }) +}) diff --git a/test/unit/editor/full-screen-set.test.ts b/test/unit/editor/full-screen-set.test.ts new file mode 100644 index 000000000..9086c04ee --- /dev/null +++ b/test/unit/editor/full-screen-set.test.ts @@ -0,0 +1,23 @@ +import createEditor, { selector } from '../../helpers/create-editor' +import { setFullScreen } from '../../../src/editor/init-fns/set-full-screen' +import $ from 'jquery' + +const EDIT_CONTAINER_FULLSCREEN_CLASS = 'w-e-full-screen-editor' + +test('调用 setFullScreen 设置编辑器全屏模式', () => { + const editor = createEditor(document, selector()) + + setFullScreen(editor) + + const toolbarSelector = editor.$toolbarElem.elems[0].className + const $iconElem = $(`.${toolbarSelector}`).children().last().find('i') + const $editorParent = $(`.${toolbarSelector}`).parent().get(0) + const $textContainerElem = editor.$textContainerElem + + expect($iconElem.get(0).className).toContain('w-e-icon-fullscreen_exit') + console.log($editorParent.className) + expect($editorParent.className).toContain(EDIT_CONTAINER_FULLSCREEN_CLASS) + expect(+$editorParent.style.zIndex).toEqual(editor.config.zIndexFullScreen) + const bar = editor.$toolbarElem.getBoundingClientRect() + expect($textContainerElem.elems[0].style.height).toBe(`calc(100% - ${bar.height}px)`) +}) diff --git a/test/unit/editor/full-screen-unset.test.ts b/test/unit/editor/full-screen-unset.test.ts new file mode 100644 index 000000000..441017261 --- /dev/null +++ b/test/unit/editor/full-screen-unset.test.ts @@ -0,0 +1,23 @@ +import createEditor, { selector } from '../../helpers/create-editor' +import { setFullScreen, setUnFullScreen } from '../../../src/editor/init-fns/set-full-screen' +import $ from 'jquery' + +const EDIT_CONTAINER_FULLSCREEN_CLASS = 'w-e-full-screen-editor' + +test.only('调用 setUnFullScreen 取消编辑器全屏模式', () => { + const editor = createEditor(document, selector()) + + setFullScreen(editor) + + setUnFullScreen(editor) + + const toolbarSelector = editor.$toolbarElem.elems[0].className + const $iconElem = $(`.${toolbarSelector}`).children().last().find('i') + const $editorParent = $(`.${toolbarSelector}`).parent().get(0) + const $textContainerElem = editor.$textContainerElem + + expect($iconElem.get(0).className).toContain('w-e-icon-fullscreen') + expect($editorParent.className).not.toContain(EDIT_CONTAINER_FULLSCREEN_CLASS) + expect($editorParent.style.zIndex).toBe('auto') + expect($textContainerElem.elems[0].style.height).toBe(editor.config.height + 'px') +}) diff --git a/test/unit/editor/history/compile.test.ts b/test/unit/editor/history/compile.test.ts index a1c47de0a..91b636fc2 100644 --- a/test/unit/editor/history/compile.test.ts +++ b/test/unit/editor/history/compile.test.ts @@ -3,7 +3,7 @@ * @author luochao */ -import createEditor from '../../../helpers/create-editor' +import createEditor, { selector } from '../../../helpers/create-editor' import Editor from '../../../../src/editor' import compile, { compileType, @@ -37,7 +37,7 @@ const originalValue = UA.isFirefox describe('Editor history compile', () => { beforeEach(() => { - editor = createEditor(document, 'div1') + editor = createEditor(document, selector()) }) afterEach(() => { @@ -74,7 +74,7 @@ describe('Editor history compile', () => { const observer = new MutationObserver((mutationList: MutationRecord[]) => { const compileData = compile(mutationList) expect(compileData instanceof Array).toBeTruthy() - expect(compileData.length).toBe(4) + expect(compileData.length).toBeGreaterThanOrEqual(4) done() }) diff --git a/test/unit/editor/history/data-html.test.ts b/test/unit/editor/history/data-html.test.ts index 106da7f9e..f6490a012 100644 --- a/test/unit/editor/history/data-html.test.ts +++ b/test/unit/editor/history/data-html.test.ts @@ -2,7 +2,7 @@ * @description Editor history data html cache * @author luochao */ -import createEditor from '../../../helpers/create-editor' +import createEditor, { selector } from '../../../helpers/create-editor' import Editor from '../../../../src/editor' import HtmlCache from '../../../../src/editor/history/data/html' @@ -10,7 +10,7 @@ let editor: Editor let htmlCache: HtmlCache describe('Editor history html cache', () => { beforeEach(() => { - editor = createEditor(document, 'div1', '', { + editor = createEditor(document, selector(), '', { compatibleMode: () => true, }) diff --git a/test/unit/editor/history/decompile.test.ts b/test/unit/editor/history/decompile.test.ts index 319e68d6a..87d29fc10 100644 --- a/test/unit/editor/history/decompile.test.ts +++ b/test/unit/editor/history/decompile.test.ts @@ -3,7 +3,7 @@ * @author luochao */ -import createEditor from '../../../helpers/create-editor' +import createEditor, { selector } from '../../../helpers/create-editor' import Editor from '../../../../src/editor' import compile from '../../../../src/editor/history/data/node/compile' import { restore, revoke } from '../../../../src/editor/history/data/node/decompilation' @@ -13,7 +13,7 @@ let editor: Editor describe('Editor history decompile', () => { beforeEach(() => { - editor = createEditor(document, 'div1') + editor = createEditor(document, selector()) }) test('可以通过revoke方法撤销编辑器设置的html', done => { diff --git a/test/unit/editor/set-full-screen.test.ts b/test/unit/editor/set-full-screen.test.ts deleted file mode 100644 index f75ac6391..000000000 --- a/test/unit/editor/set-full-screen.test.ts +++ /dev/null @@ -1,68 +0,0 @@ -import createEditor from '../../helpers/create-editor' -import Editor from '../../../src/editor/index' -import { setFullScreen, setUnFullScreen } from '../../../src/editor/init-fns/set-full-screen' -import $ from 'jquery' - -let editor: Editor -const FULLSCREEN_MENU_CLASS_SELECTOR = '.w-e-icon-fullscreen' -const EDIT_CONTAINER_FULLSCREEN_CLASS = 'w-e-full-screen-editor' - -describe('设置全屏', () => { - beforeEach(() => { - editor = createEditor(document, 'div1') - }) - - test('编辑器默认初始化全屏菜单', () => { - const toolbarSelector = editor.$toolbarElem.elems[0].className - const fullMenuEl = $(`.${toolbarSelector}`).find(FULLSCREEN_MENU_CLASS_SELECTOR) - - expect(fullMenuEl.length).toBe(1) - }) - - test('编辑器区和菜单分离的编辑器不初始化全屏菜单', () => { - const seprateModeEditor = createEditor(document, 'div1', 'div2') - const toolbarSelector = seprateModeEditor.$toolbarElem.selector as string - const fullMenuEl = $(toolbarSelector).find(FULLSCREEN_MENU_CLASS_SELECTOR) - - expect(fullMenuEl.length).toBe(0) - }) - - test('编辑器配置 showFullScreen 为false时不初始化全屏菜单', () => { - const seprateModeEditor = createEditor(document, 'div1', '', { showFullScreen: false }) - const toolbarSelector = seprateModeEditor.$toolbarElem.selector as string - const fullMenuEl = $(toolbarSelector).find(FULLSCREEN_MENU_CLASS_SELECTOR) - - expect(fullMenuEl.length).toBe(0) - }) - - test('调用 setFullScreen 设置编辑器全屏模式', () => { - setFullScreen(editor) - - const toolbarSelector = editor.$toolbarElem.elems[0].className - const $iconElem = $(`.${toolbarSelector}`).children().last().find('i') - const $editorParent = $(`.${toolbarSelector}`).parent().get(0) - const $textContainerElem = editor.$textContainerElem - - expect($iconElem.get(0).className).toContain('w-e-icon-fullscreen_exit') - expect($editorParent.className).toContain(EDIT_CONTAINER_FULLSCREEN_CLASS) - expect(+$editorParent.style.zIndex).toEqual(editor.config.zIndexFullScreen) - const bar = editor.$toolbarElem.getBoundingClientRect() - expect($textContainerElem.elems[0].style.height).toBe(`calc(100% - ${bar.height}px)`) - }) - - test('调用 setUnFullScreen 取消编辑器全屏模式', () => { - setFullScreen(editor) - - setUnFullScreen(editor) - - const toolbarSelector = editor.$toolbarElem.elems[0].className - const $iconElem = $(`.${toolbarSelector}`).children().last().find('i') - const $editorParent = $(`.${toolbarSelector}`).parent().get(0) - const $textContainerElem = editor.$textContainerElem - - expect($iconElem.get(0).className).toContain('w-e-icon-fullscreen') - expect($editorParent.className).not.toContain(EDIT_CONTAINER_FULLSCREEN_CLASS) - expect($editorParent.style.zIndex).toBe('auto') - expect($textContainerElem.elems[0].style.height).toBe(editor.config.height + 'px') - }) -}) diff --git a/test/unit/menus/custom-menu.test.ts b/test/unit/menus/custom-menu.test.ts index 29514ffcc..9b72da8a4 100644 --- a/test/unit/menus/custom-menu.test.ts +++ b/test/unit/menus/custom-menu.test.ts @@ -3,13 +3,17 @@ * @author wangfupeng */ -import createEditor from '../../helpers/create-editor' +import createEditor, { selector } from '../../helpers/create-editor' import Editor from '../../../src/wangEditor' const { BtnMenu, DropListMenu, PanelMenu, DropList, Panel, Tooltip } = Editor let editor: Editor +beforeEach(() => { + editor = createEditor(document, selector()) +}) + // 创建 menu 的各个 class test('自定义菜单的 class', () => { expect(BtnMenu).not.toBeNull() @@ -39,8 +43,6 @@ test('实例注册扩展一个菜单', () => { tryChangeActive() {} } - // 创建编辑器实例 - editor = createEditor(document, 'div1') // 赋值给全局变量,便于再扩展测试用例 // 注册菜单 editor.menus.extend('insertABC', InsertABCMenu) @@ -66,8 +68,6 @@ test('全局注册扩展一个菜单', () => { // 注册菜单 Editor.registerMenu('insertXYZ', InsertABCMenu) - // 创建编辑器实例 - editor = createEditor(document, 'div1') expect(editor.menus.constructorList.insertABC).not.toBeNull() }) diff --git a/test/unit/menus/img/paste-img.test.ts b/test/unit/menus/img/paste-img.test.ts index c633f432e..a69e7c337 100644 --- a/test/unit/menus/img/paste-img.test.ts +++ b/test/unit/menus/img/paste-img.test.ts @@ -2,12 +2,15 @@ * @description Img menu paste-img * @author luochao */ -import createEditor from '../../../helpers/create-editor' +import createEditor, { selector } from '../../../helpers/create-editor' import bindPasteImgEvent from '../../../../src/menus/img/bind-event/paste-img' import UploadImg from '../../../../src/menus/img/upload-img' import mockFile from '../../../helpers/mock-file' import mockCmdFn from '../../../helpers/command-mock' import * as pasteEvents from '../../../../src/text/paste/paste-event' +import Editor from '../../../../src/editor' + +let editor: Editor const mockFiles = [mockFile({ name: 'test.png', size: 200, mimeType: 'image/png' })] const mockUploadImg = jest.fn() @@ -23,11 +26,10 @@ describe('Img menu paste-img', () => { // @ts-ignore UploadImg.mockClear() mockUploadImg.mockClear() + editor = createEditor(document, selector()) }) test('调用 bindPasteImgEvent 方法给编辑器绑定paste事件', () => { - const editor = createEditor(document, 'div1') - bindPasteImgEvent(editor) expect(editor.txt.eventHooks.pasteEvents.length).toBeGreaterThanOrEqual(1) @@ -40,8 +42,6 @@ describe('Img menu paste-img', () => { mock.mockReturnValue(mockFiles) - const editor = createEditor(document, 'div1') - bindPasteImgEvent(editor) const mockGetData = jest.fn().mockImplementation(() => '') @@ -65,8 +65,6 @@ describe('Img menu paste-img', () => { mock.mockReturnValue([]) - const editor = createEditor(document, 'div1') - bindPasteImgEvent(editor) const mockGetData = jest.fn().mockImplementation(() => '') @@ -89,8 +87,6 @@ describe('Img menu paste-img', () => { mock.mockReturnValue(mockFiles) - const editor = createEditor(document, 'div1') - bindPasteImgEvent(editor) const mockGetData = jest.fn().mockImplementation(() => '') @@ -113,8 +109,6 @@ describe('Img menu paste-img', () => { mock.mockReturnValue(mockFiles) - const editor = createEditor(document, 'div1') - bindPasteImgEvent(editor) const mockGetData = jest.fn().mockImplementation((type: string) => { diff --git a/test/unit/text/paste-text-html.test.ts b/test/unit/text/paste-text-html.test.ts index 05a5ec07a..740ae6f62 100644 --- a/test/unit/text/paste-text-html.test.ts +++ b/test/unit/text/paste-text-html.test.ts @@ -3,14 +3,14 @@ * @author luochao */ import pasteTextHtml from '../../../src/text/event-hooks/paste-text-html' -import createEditor from '../../helpers/create-editor' +import createEditor, { selector } from '../../helpers/create-editor' import * as pasteEvents from '../../../src/text/paste/paste-event' import $ from '../../../src/utils/dom-core' import mockCommand from '../../helpers/command-mock' describe('text utils getPasteImgs test', () => { test('执行函数会绑定一个 pasteEvents handler', () => { - const editor = createEditor(document, 'div1') + const editor = createEditor(document, selector()) const pasteEvents: Function[] = [] pasteTextHtml(editor, pasteEvents) @@ -18,7 +18,7 @@ describe('text utils getPasteImgs test', () => { }) test('如果当前选区所在元素不存在,执行 pasteEvents 的函数直接返回', () => { - const editor = createEditor(document, 'div2') + const editor = createEditor(document, selector()) const pasteEventList: Function[] = [] pasteTextHtml(editor, pasteEventList) @@ -41,7 +41,7 @@ describe('text utils getPasteImgs test', () => { jest.spyOn(document, 'queryCommandSupported').mockImplementation(() => true) const mockPasteTextHandle = jest.fn(() => 'mock123
') - const editor = createEditor(document, 'div3', '', { + const editor = createEditor(document, selector(), '', { pasteTextHandle: mockPasteTextHandle, }) @@ -68,7 +68,7 @@ describe('text utils getPasteImgs test', () => { jest.spyOn(document, 'queryCommandSupported').mockImplementation(() => true) - const editor = createEditor(document, 'div4') + const editor = createEditor(document, selector()) const pasteEventList: Function[] = [] @@ -98,7 +98,7 @@ describe('text utils getPasteImgs test', () => { jest.spyOn(document, 'queryCommandSupported').mockImplementation(() => true) - const editor = createEditor(document, 'div4') + const editor = createEditor(document, selector()) const pasteEventList: Function[] = [] @@ -121,7 +121,7 @@ describe('text utils getPasteImgs test', () => { jest.spyOn(document, 'queryCommandSupported').mockImplementation(() => true) - const editor = createEditor(document, 'div4') + const editor = createEditor(document, selector()) const pasteEventList: Function[] = [] @@ -145,7 +145,7 @@ describe('text utils getPasteImgs test', () => { jest.spyOn(document, 'queryCommandSupported').mockImplementation(() => true) const mockPasteTextHandle = jest.fn(() => '
123

') - const editor = createEditor(document, 'div3', '', { + const editor = createEditor(document, selector(), '', { pasteTextHandle: mockPasteTextHandle, }) @@ -178,7 +178,7 @@ describe('text utils getPasteImgs test', () => { const mockPasteTextHandle = jest.fn(() => '
123

') - const editor = createEditor(document, 'div3', '', { + const editor = createEditor(document, selector(), '', { pasteTextHandle: mockPasteTextHandle, }) @@ -204,7 +204,7 @@ describe('text utils getPasteImgs test', () => { jest.spyOn(pasteEvents, 'getPasteHtml').mockImplementation(() => '

1234

') - const editor = createEditor(document, 'div4') + const editor = createEditor(document, selector()) const pasteEventList: Function[] = [] pasteTextHtml(editor, pasteEventList) diff --git a/test/unit/text/tab-to-space.test.ts b/test/unit/text/tab-to-space.test.ts index d8624b467..861d223de 100644 --- a/test/unit/text/tab-to-space.test.ts +++ b/test/unit/text/tab-to-space.test.ts @@ -4,13 +4,19 @@ */ import tabHandler from '../../../src/text/event-hooks/tab-to-space' import $ from '../../../src/utils/dom-core' -import createEditor from '../../helpers/create-editor' +import createEditor, { selector } from '../../helpers/create-editor' import mockCommand from '../../helpers/command-mock' +import Editor from '../../../src/editor' describe('editor.text event-hooks tab-to-space test', () => { + let editor: Editor + + beforeEach(() => { + editor = createEditor(document, selector()) + }) + test('能绑定一个处理 tab 的函数', () => { const fn: Function[] = [] - const editor = createEditor(document, 'div1') tabHandler(editor, fn) @@ -21,7 +27,6 @@ describe('editor.text event-hooks tab-to-space test', () => { mockCommand(document) const fn: Function[] = [] - const editor = createEditor(document, 'div1') jest.spyOn(editor.cmd, 'queryCommandSupported').mockImplementation(() => false) @@ -38,7 +43,6 @@ describe('editor.text event-hooks tab-to-space test', () => { mockCommand(document) const fn: Function[] = [] - const editor = createEditor(document, 'div1') jest.spyOn(editor.cmd, 'queryCommandSupported').mockImplementation(() => true) jest.spyOn(editor.selection, 'getSelectionContainerElem').mockImplementation( @@ -58,7 +62,6 @@ describe('editor.text event-hooks tab-to-space test', () => { mockCommand(document) const fn: Function[] = [] - const editor = createEditor(document, 'div1') jest.spyOn(editor.cmd, 'queryCommandSupported').mockImplementation(() => true) const container = $('


') @@ -80,11 +83,10 @@ describe('editor.text event-hooks tab-to-space test', () => { mockCommand(document) let editor: ReturnType - let id = 1 let fn: Function[] = [] beforeEach(() => { - editor = createEditor(document, `div${id++}`) + editor = createEditor(document, selector()) tabHandler(editor, fn)