使用@testing-library/react 对ReactEditorCompoent进行单元测试问题 #2108
Unanswered
yinyinfurong8888
asked this question in
Q&A
Replies: 1 comment
-
@yinyinfurong8888 目前直接基于 Editor 组件做单元测试写起来是相对困难的,框架中推荐的测试方式是基于 Playwright 去做 E2E 测试,基于我们提供的 相关内容: 你可以基于 import { OpenSumiApp } from '@opensumi/playwright';
export class MyOpenSumiApp extends OpenSumiApp {
} import { expect, Page, test } from '@playwright/test';
import { MyOpenSumiApp } from './my-app';
let page: Page;
let app: MyOpenSumiApp;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
app = await MyOpenSumiApp.loadApp(page, MyOpenSumiApp);
});
test.describe('My OpenSumi application', () => {
test('should show main content panel', async () => {
expect(await app.isMainContentPanelVisible()).toBe(true);
});
}); 单元测试不太适用于基于 OpenSumi 搭建的项目,你可以仅对自定义的函数或方法采用 Jest / mocha 等测试库进行测试。 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
opensumi 编辑器组件定义后,需要注册编辑器组件registerEditorComponent,然后editorService.open打开对应的uid 的resouce,
当使用@testing-library/react 对编辑器组件进行测试时, render 方法需要ReactElement类型,我如何能找到编辑器组件的对应的类型呢,目前是ReactEditorComponent, 是个类型
export declare type ReactEditorComponent<MetaData = any> = React.ComponentType<{ resource: IResource<MetaData>; }>;
被测编辑器组件:
const TestComponent: ReactEditorComponent<any> = ({ resource }) => {...}
测试代码:
@testing-library/react 需要ReactElement类型,但TestCompoent类型只是个type, 报错,我这边看了registerEditorComponent以及editorService.open相关的源码,也没有找到对应编辑器组件类型转ReactElement 的方法,想请教下是否有暴露编辑器组件实例的方法,opensumi 推荐的单元测试工具库是什么呢?
其他:对应贡献点:
Beta Was this translation helpful? Give feedback.
All reactions