我一直在尝试测试以下方法,但是有点卡住了。这是主要的file.js和file.test.js的一部分
主文件js。
handleSaveAsNameChange = (e) => {
this.setState({saveAsName: e.target.value}, () => {
this.updateHomeScreen();
});
}
updateHomeScreen = debounce(() => {
this.props.setSaveAsName(this.state.saveAsName)
}, 250)
render() {
<div title="Close Window Without Saving" className="sidemodal_addnew_x"
onClick={() => {this.props.closeSaveAsModal()}}><FontAwesome name='xbutton'
className='fa-times' /></div>
<input autoFocus className="modal-add-window-input" placeholder="New
view name" value={this.state.saveAsName} onChange={(e) =>
{this.handleSaveAsNameChange(e)}}/>
<button className='close_button_layout' title='Save' type='button'
onClick={() => {this.props.saveAsView()}}>Create</button>
测试file.js 到目前为止,我已经设置了this.prop:怎样改进以下测试。另外,我将大多数渲染与下面的代码放在一起,但OnClick不会显示在快照上
it(' Should render with all of the props', () => {
tree = renderer.create(<SaveViewAsModal {...baseProps} />)
let treeJson = tree.toJSON()
expect(treeJson).toMatchSnapshot();
tree.unmount()
});
it('handleSaveAsNameChange method ', () => {
const value = 250;
wrapper.instance(). handleSaveAsNameChange({ target: { value } });
expect(wrapper).toMatchSnapshot();
});
});