【发布时间】:2017-10-10 19:07:21
【问题描述】:
我正在使用 Jest 和 Enzyme 来测试一个 React 复选框组件。
这是我的测试:
it('triggers checkbox onChange event', () => {
const configs = {
default: true,
label: 'My Label',
element: 'myElement',
}
const checkbox = shallow(
<CheckBox
configs={configs}
/>
)
checkbox.find('input').simulate('click')
})
但是在运行测试时出现此错误:
TypeError: Cannot read property 'target' of undefined
这是我的组件的输入:
<div className="toggle-btn sm">
<input
id={this.props.configs.element}
className="toggle-input round"
type="checkbox"
defaultChecked={ this.props.defaultChecked }
onClick={ e => this.onChange(e.target) }
>
</input>
</div>
我认为 I need to pass an event as the second object to simulate 但我不知道该怎么做。
谢谢
【问题讨论】:
标签: javascript reactjs jestjs enzyme