tmagic-editor/packages/editor/tests/unit/utils/monaco-editor.spec.ts
2026-05-14 15:26:22 +08:00

32 lines
862 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Tencent is pleased to support the open source community by making TMagicEditor available.
*
* Copyright (C) 2025 Tencent.
*/
import { describe, expect, test, vi } from 'vitest';
import getMonaco from '@editor/utils/monaco-editor';
vi.mock('emmet-monaco-es', () => ({
emmetHTML: vi.fn(),
emmetCSS: vi.fn(),
}));
vi.mock('monaco-editor', () => ({
default: { editor: {}, languages: {} },
editor: {},
languages: {},
}));
describe('monaco-editor 加载器', () => {
test('返回 Promise且会缓存复用同一个实例', async () => {
const p1 = getMonaco();
const p2 = getMonaco();
expect(p1).toBe(p2);
const monaco = await p1;
const emmet = await import('emmet-monaco-es');
expect(emmet.emmetHTML).toHaveBeenCalledWith(monaco);
expect(emmet.emmetCSS).toHaveBeenCalledWith(monaco, ['css', 'scss']);
});
});