模拟的getData()方法单击Test,在模拟后会产生以下结果,
TypeError:无法读取null的属性“值”
68 | //
69 | getData(){
> 70 | const elementName = (document.getElementById("sample-element") ;
// Test Case follows..
it('Check for getData', () => {
getData = sinon.spy(wrapper.instance(), 'getData');
wrapper.update();
wrapper.find('#getData').simulate('click');
expect(getData.called).toBe(true);
getData.restore();
});
getData(){
const elementName = (document.getElementById("sample-element");
fetch(config.getRowDataAPI+elementName)
.then(response => response.json())
.then(allRowData => this.setState({ allRowData },
() => {
this.setTable(this.state.allRowData);
}
));
}