Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs Jest模拟Typescript中的非默认子组件将返回错误_Reactjs_Ts Jest - Fatal编程技术网

Reactjs Jest模拟Typescript中的非默认子组件将返回错误

Reactjs Jest模拟Typescript中的非默认子组件将返回错误,reactjs,ts-jest,Reactjs,Ts Jest,当使用Jest模拟子组件并使用Typescript时,测试将返回一个错误 复制 复制行为的步骤: 创建子组件: export const MyChildComponent = () => { return ( <> <span>Something there.</span> </> ); }; const MyChildComponent = () => { return ( <&

当使用Jest模拟子组件并使用Typescript时,测试将返回一个错误

复制 复制行为的步骤:
创建子组件:

export const MyChildComponent = () => {
  return (
    <>
      <span>Something there.</span>
    </>
  );
};
const MyChildComponent = () => {
  return (
    <>
      <span>Something there.</span>
    </>
  );
};
export default MyChildComponent;
预期行为 根据测试实现,测试不应返回错误和通过/失败


这与3天前关闭的组件有关,可能会得到解决。

因此,我发现问题在于我的子组件没有作为
默认值导出。考虑到我的
tsconfig.js
(通过CreateReact应用程序引导程序创建),我必须更改导出子组件的方式:

export const MyChildComponent = () => {
  return (
    <>
      <span>Something there.</span>
    </>
  );
};
const MyChildComponent = () => {
  return (
    <>
      <span>Something there.</span>
    </>
  );
};
export default MyChildComponent;
constmychildcomponent=()=>{
返回(
那里有些东西。
);
};
导出默认MyChildComponent;
并在使用导入时删除导入中的
{}

const MyChildComponent = () => {
  return (
    <>
      <span>Something there.</span>
    </>
  );
};
export default MyChildComponent;