reactjs - 在 Enzyme 中查找 ref 进行测试
问题描述
有测试代码:
it('componentDidUpdate should mount and change props', () => {
const onChange = jest.fn();
const wrapper = enzyme
.mount(
withTestTheme(
<JsonInput
onChange={onChange}
onValueChange={mockOnValueChange}
value={exampleJsonStringValidated}
/>),
);
expect(wrapper.instance().JsonInputRef).toBeTruthy;
});
我有:
“组件<{}、{}、任何>”类型上不存在属性“JsonInputRef”。ts(2339)
我想找到 ref (文本区域),然后检查有效性属性以编写单元测试,这就是我需要它的原因。
渲染功能:
render() {
const { height = '', onValueChange, ...restProps } = this.props;
return (
<StyledTextArea
ref={this.JsonInputRef}
{...restProps}
onChange={this.handleValueChange}
height={height}
/>
);
}
类似的问题,但不起作用:React/JestJS/Enzyme: How to test for reference function?
解决方案
推荐阅读
- r - 两条斜线,一条用于最小点,另一条用于R中散点图中的最大点
- hive - 为什么这个子查询 hiveql 不起作用?
- javascript - 我可以在javascript中用字符串名称调用一些帮助函数吗
- typo3 - PHP strict_types 和与不可见 TYPO3 记录的关系
- django - django频道安装错误
- python - 将数据框中的字典列表转换为字符串列表 - 熊猫
- php - 无法通过 Phonegap 和 PHP 将图像上传到 Linux 服务器
- php - 将多个外部 MSSQL 表中的多个组合 PHP 表单数据添加到一个主表中
- ios - UIAlertController 在警报操作时移动到另一个控制器 - Swift
- ios - 如何在 iOS 中实现彗星聊天时修复“无效的 API 密钥格式”