Reactjs 我有一个关于JSX.Element的道具。我如何在玩笑测试中模仿同样的东西

Reactjs 我有一个关于JSX.Element的道具。我如何在玩笑测试中模仿同样的东西,reactjs,typescript,jestjs,Reactjs,Typescript,Jestjs,我是我的反应组件,我有下面这样的道具 interface Props { errorMessage: JSX.Element; addCommentCancel: () => void; triggerAddComment: () => void; showAddCommentForm: boolean; } const props = { errorMessage: {}, addCommentCancel: () => jest.fn(),

我是我的反应组件,我有下面这样的道具

interface Props {
  errorMessage: JSX.Element;
  addCommentCancel: () => void;
  triggerAddComment: () => void;
  showAddCommentForm: boolean;
}
const props =  {
  errorMessage: {},
  addCommentCancel: () => jest.fn(),
  triggerAddComment: () => jest.fn(),
  showAddCommentForm: true
};
let wrapper = mount(<IncidentCommentList {...props} />);
在测试中,我调用了如下组件

interface Props {
  errorMessage: JSX.Element;
  addCommentCancel: () => void;
  triggerAddComment: () => void;
  showAddCommentForm: boolean;
}
const props =  {
  errorMessage: {},
  addCommentCancel: () => jest.fn(),
  triggerAddComment: () => jest.fn(),
  showAddCommentForm: true
};
let wrapper = mount(<IncidentCommentList {...props} />);
如何模拟道具元素?

const-props={
const props =  {
  errorMessage: <div>errorMessage</div>,
  addCommentCancel: () => jest.fn(),
  triggerAddComment: () => jest.fn(),
  showAddCommentForm: true
};
let wrapper = mount(<IncidentCommentList {...props} />);
errorMessage:errorMessage, addCommentCancel:()=>jest.fn(), TriggeradComment:()=>jest.fn(), showAddCommentForm:true }; 让wrapper=mount();
上面的代码修复了这个问题

const props={
errorMessage:errorMessage,
addCommentCancel:()=>jest.fn(),
TriggeradComment:()=>jest.fn(),
showAddCommentForm:true
};
让wrapper=mount();

上面的代码修复了这个问题

正如它的名字所说,
JSX.Element
代表JSX元素(例如,
),或者是一个字符串。也许
null
也可以,但我不确定。在React或DefinitelyTypes中未找到
JSX.Element
声明,因此未按照其名称填写“官方答案”,因为
JSX.Element
表示JSX元素(例如
)或是字符串。也许
null
也可以,但我不确定。在React或DefinitelyTypes中未找到
JSX.Element
声明,因此未填写“官方答案”,测试使用的文件扩展名是什么?我在一个.ts文件中出错。您在测试中使用的文件扩展名是什么?我得到一个.ts文件错误。