如何测试是否选中了多个复选框?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
我尝试过
render()
...
<React.Fragment>
<div
className='foo'>
<label>
<input
className='checkbox'
name='bar'
type='checkbox'
checked={this.props.checked}
onChange={() => { } }
/>
</label>
</div>
</React.Fragment>
...
和
it('checks all checkboxes', () => {
const component = shallow(
<Foo
... />
)
expect(component
.find('input[type="checkbox"][checked="checked"]'))
.toHaveLength(content.length);
});
或
component
.find({ type: 'checkbox' })
.forEach(node => {
expect(node
.props
.checked)
.toEqual(true);
});
和
component
.find('input')
.forEach(node => {
expect(node
.props
.checked)
.toEqual(true);
});
最后三个给了我component
.find('.checkbox')
.forEach(node => {
expect(node
.props
.checked)
.toEqual(true);
});
,而第三个给了我一个巨大的物体(undefined