// 空文档占位:空文档首段挂 .doc-placeholder(CSS 显示「开始输入…」),有内容时不挂。 import { describe, it, expect, afterEach } from 'vitest' import type { Editor } from '@milkdown/kit/core' import { createMarkdownEditor } from '../src/editor/editor' let editors: Editor[] = [] afterEach(async () => { for (const e of editors) { try { await e.destroy() } catch { /* ignore */ } } editors = [] document.body.innerHTML = '' }) async function load(md: string): Promise { const root = document.createElement('div') document.body.appendChild(root) const editor = createMarkdownEditor(root, md) editors.push(editor) await editor.create() return root } describe('空文档占位', () => { it('空文档有占位类,非空文档没有', async () => { const emptyRoot = await load('') expect(emptyRoot.querySelector('.doc-placeholder')).not.toBeNull() const filledRoot = await load('# 标题\n\n正文') expect(filledRoot.querySelector('.doc-placeholder')).toBeNull() }) })