Jam*_*son 3 testing typescript reactjs enzyme
我在 React 中设计了一个组件,其中包含一个只能设置的输入字段,因此必须是只读的,但无法弄清楚如何测试此输入在 Enzyme 中是否为只读。
我找不到有关 readOnly 属性的任何内容,但有人对Test if an Input is disabled有类似的问题。由此看来我需要使用类似下面的代码的东西。
test('select button select input must be read only', () => {
expect(select.find('div').find('div').find('input').hasAttribute('readOnly', 'true').toBeTruthy();
});
Run Code Online (Sandbox Code Playgroud)
但是,hasAttributeShallowWrapper 类型无法识别,并且上面链接中的所有其他方法都无法识别。
只是为了澄清我的输入字段如下。
<input readOnly={true} type="text" placeholder={selectedOption} />
Run Code Online (Sandbox Code Playgroud)
以前有人遇到过这种情况吗?我如何使用 Enzyme 来测试此输入是否为只读?
由于它是一个经过测试的组件,而不是 React 将其渲染到 DOM 的方式,因此它可以是:
expect(shallow(<Comp/>).find('div div input').prop('readOnly')).toBe(true);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8131 次 |
| 最近记录: |