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