- 为 `renderTaroComponent` 函数添加明确的 `RenderResult` 返回类型,提升类型安全性 - 在 `tsconfig.json` 的 `types` 数组中添加 `"node"` 类型定义,以支持 Node.js 环境下的类型检查
@@ -1,7 +1,7 @@
// 测试工具函数
-import { render } from '@testing-library/react'
+import { render, type RenderResult } from '@testing-library/react'
-export const renderTaroComponent = (component: React.ReactElement, options?: any) => {
+export const renderTaroComponent = (component: React.ReactElement, options?: any): RenderResult => {
return render(component, options)
}
@@ -18,7 +18,7 @@
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
- "types": ["react"]
+ "types": ["react", "node"]
},
"include": ["src/**/*", "tests"],
"exclude": ["node_modules", "dist"]