我正在用酶和Jest测试React应用程序。该应用程序具有一组表示api列表的复选框。每次单击这样的复选框(触发onChange)时,都会将其服务id添加到应用程序的状态中,以便呈现输入
选中的
.
state = {
checkedServicesIds: []
}
规格:
it.only('should check and uncheck services when clicked', () => {
wrapper.setProps({ [{ id: 0, name: 'The Super API' }, { id: 1, name: 'Cool Villains Hub' }] })
wrapper.setState({ checkedServicesIds: [] })
const input0 = wrapper.find(`input#service_ids_${0}`)
const input1 = wrapper.find(`input#service_ids_${1}`)
expect(input0.prop('checked')).toBe(false)
expect(input1.prop('checked')).toBe(false)
input0.simulate('change')
expect(wrapper.state('checkedServicesIds')).toEqual([0])
expect(wrapper.find(`input#service_ids_${0}`).prop('checked')).toBe(true)
expect(input0.prop('checked')).toBe(true)
})
我不是在用吗
update
正确地?