【发布时间】:2019-05-14 12:53:24
【问题描述】:
这是我尝试测试按钮的点击事件
it('should call addItem when button is clicked', () => {
const addItem = jest.fn()
const button = mount(<App onClick={addItem} />)
//button.find('button').props.onClick()
//expect(addItem).toBeCalled()
})
这是 DOM
<div className="App">
<input type="text" onChange={this.changeInput} />
<button onClick={this.addItem}>Add</button>
</div>
错在哪里?
【问题讨论】:
-
尝试使用
button.find('button').simulate('click')。此外,您可能希望将其从button重命名为更合适的名称,例如wrapper或component。 -
@AnaLizaPandac 差不多了,但仍然无法断言 codesandbox.io/s/mk6r923r8
标签: javascript ecmascript-6 jestjs enzyme