【发布时间】:2019-02-25 15:42:06
【问题描述】:
我有一个组件,其中包含已将功能分配给 ref 的输入,我尝试为它编写测试:
<input
id="input-element"
type="checkbox"
checked={isChecked}
ref={(input) => {
if (input) {
input.indeterminate = true;
}
}}
className="checkbox" />
我的问题是如何检查输入不确定是否设置为真。文档https://airbnb.io/enzyme/docs/api/ReactWrapper/ref.html 对我没有帮助,因为只有非常简单和无用的示例。
我尝试过这样测试:
const wrapper = shallow(<MyComponent {...props}/>);
expect(wrapper.find('#input-element').prop('indeterminate')).toBeTruthy();
但是wrapper.find('#input-element').prop('indeterminate') 回复我undefined
【问题讨论】:
标签: javascript reactjs enzyme