栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

测试函数是否称为反应和酶

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

测试函数是否称为反应和酶

有两种选择,要么

_handleCloneClick
在呈现组件之前就监视组件的原型,要么:

export default class cloneButton extends Component {  constructor(...args) {    super(...args);    this. _handleCloneClick = this. _handleCloneClick.bind(this);  }  _handleCloneClick() {    event.preventDefault();    event.stopPropagation();    this.props.handleClone(this.props.user.id);  }  render() {    return (<button onClick={this. _handleCloneClick}>Clone</button>);  }}

在您的测试中:

it('clone should call handleCloneClick when clicked', () => {  sinon.spy(cloneButton.prototype, '_handleCloneClick');  const wrapper = mount(<cloneButton/>);  wrapper.find('#clone-btn').simulate('click');  expect(spy).toHaveBeenCalled() //adept assertion to the tool you use});

或者,您可以尝试在渲染组件后设置间谍并

wrapper.update()
随后调用:

it('clone should call handleCloneClick when clicked', () => {        const wrapper = mount(<cloneButton/>);  sinon.spy(wrapper.instance(), "_handleCloneClick");  wrapper.update();  wrapper.find('#clone-btn').simulate('click');  expect(spy).toHaveBeenCalled() //adept assertion to the tool you use});


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/427254.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号