尝试使用Jest / Enzyme for React js测试onChange事件 此刻测试通过了,但是当我运行npm test coverage时,覆盖率没有变化。 我的设定状态可能有问题吗?
这是我的测试文件的一部分:
beforeEach(() => (wrapper = mount(
<MemoryRouter keyLength={0}>
<Notifications {...baseProps} />
</MemoryRouter>
)));
it("should call onChange event on checkboxCell", () => {
wrapper.find('Notifications').setState({
data:[{
Notification_UID:[]
}],
selectedRows:[],
selectedRowsValues:'test',
});
wrapper.update()
wrapper.find('Notifications')
.find('.grid-checkbox')
.simulate('change',{target: {value: 'testing1'}} )
expect(wrapper.find('Notifications').state().selectedRowsValues)
.toEqual('test');
});
还尝试了以下操作:
wrapper.find('Notifications').find('.grid-checkbox').simulate('change',{data: [{Notification_UID: 'testing1'}]} )
这是code.js
checkboxCell = (cellInfo) => {
return (
<div className='grid-checkbox'>
<input
id={cellInfo.index + cellInfo.column.id}
type='checkbox'
className={cellInfo.viewIndex%2 === 0 ? 'custom-grid-input even-row' : 'custom-grid-input odd-row'}
key={cellInfo.index + cellInfo.column.id}
disabled={false}
onChange={(e) => {this.handleRowSelect(this.state.data[cellInfo.index].Notification_UID , this.state.data[cellInfo.index])}}
checked={this.state.selectedRows.includes(this.state.data[cellInfo.index].Notification_UID)}
/>