小编Edg*_*sos的帖子

导出的函数未定义

我在 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)

javascript mocha.js commonjs typescript babeljs

1
推荐指数
1
解决办法
968
查看次数

标签 统计

babeljs ×1

commonjs ×1

javascript ×1

mocha.js ×1

typescript ×1