我在 Typescript 中遇到了 Mocha 测试的问题,我担心它与 Babel 有关,但我真的不确定发生了什么。
本质上,我有一个正在导出到文件中的函数
// src/my-ts-lib/tests/components/factoryMocks/componentConfigMocks.ts
...
export function getRandomConfig(type?: string): ComponentConfig {
const randomComponentType = type || randomType();
return {
type: randomComponentType,
config: configLibrary[randomComponentType]
}
}
Run Code Online (Sandbox Code Playgroud)
并被导入到另一个被测试调用的地方:
// src/my-ts-lib/tests/components/RouteComponent/mocks/routeMocks.ts
...
import { getRandomConfig } from '../../factoryMocks/componentConfigMocks';
..
export const getSingleRouteConfigMock = (componentType?: string): RouteProps => {
const defaultComponentType = 'PageLayout';
return {
childComponent: {
type: componentType || defaultComponentType,
config: getRandomConfig(componentType || defaultComponentType)
},
pageName: randomString(),
path: randomString(),
};
};
...
Run Code Online (Sandbox Code Playgroud)
运行测试时,我收到以下错误:
RouteCompnent/mocks/routeMocks.ts:10
config: getRandomConfig(componentType || …Run Code Online (Sandbox Code Playgroud)