Rankin Zheng 06a2582892 feat: Add tests for codeBlockHandler functionality
- Implement unit tests for creating and opening files with various content
- Introduce mocks for vscode API to simulate file creation and opening
- Cover edge cases such as unsupported languages and missing content
2024-04-15 22:50:51 +08:00

39 lines
1.1 KiB
JavaScript
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.

// test/mocks/vscode.js
// 定义一个模拟的openTextDocument函数
function openTextDocumentMock() {
return new Promise(resolve => {
// 模拟异步返回一个文档对象
resolve({
// 根据需要模拟文档对象的属性和方法
getText: () => "模拟文档内容",
// 其他需要模拟的方法和属性
});
});
}
// 定义一个模拟的showTextDocument函数
function showTextDocumentMock(document, options) {
return new Promise(resolve => {
// 模拟异步打开文档的行为
resolve({
// 模拟视图或编辑器的响应
// 例如:
viewColumn: options?.viewColumn,
// 其他需要模拟的方法和属性
});
});
}
// 导出一个对象该对象模拟vscode模块的一些API
module.exports = {
workspace: {
openTextDocument: openTextDocumentMock,
// 其他workspace下需要模拟的API
},
window: {
showTextDocument: showTextDocumentMock,
// 其他window下需要模拟的API
},
// 根据需要继续添加其他模拟的vscode API
};