3
Jest and Enzyme을 사용하여 React 확인란 구성 요소를 테스트하고 있습니다. 이것은 내 구성 요소에 대한 입력이이벤트 객체를 효소에 전달 .simulate
TypeError: Cannot read property 'target' of undefined
입니다 : 테스트를 실행할 때 나는 그러나이 오류가
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')
})
:
이
내 테스트입니다<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 생각해. 그 I need to pass an event as the second object to simulate
하지만 어떻게 해야할지 모르겠다. 이.
예! 이 작동합니다. 감사! – SeanPlusPlus
@SeanPlusPlus 당신은 환영합니다 :) – madox2