我正在为ReactJs应用程序运行 mocha + 酶测试。在调试时,我得到以下内容:
<div id="login" className="card">
<div>
<h1>
Welcome
</h1>
<p>
Login to manage your business.
</p>
<div className="tabs">
<i onClick={[Function]} data-tab="0" className="fa fa-phone active" aria-hidden="true" />
<i onClick={[Function]} data-tab="1" className="fa fa-at" aria-hidden="true" />
</div>
<div className="inputs">
<PhoneNumber countryData={{...}}
suggestions={{...}}
onChange={[Function]}
onSubmit={[Function]}
autofocus={true}
value="123456789"
selectedCountry="India"
validationHandler={[Function]} />
</div>
<button className="button" type="button" onClick={[Function]}>
Continue
</button>
</div>
</div>
每当我尝试模拟点击操作时,它都会返回false。
我在这里附上我的测试脚本:
const wrapper = shallow(<Login onSubmit={onButtonClick} />);
wrapper.setState({ tab: 0 });
wrapper.setState({ clientNumber: '123456798' });
wrapper.setState({clientCountry: "India"});
wrapper.setProps({ countryData: {"name": "India","dial_code": "+91","code": "IN"}});
wrapper.setProps({suggestions: ["Iraq", "Ireland"]});
console.log(wrapper.debug());
expect(wrapper.find('button')).to.have.length(1); #passing and return true
const onButtonClick = sinon.spy();
wrapper.find('button').last().simulate('click');
expect(onButtonClick.calledOnce).to.equal(true); #return false
我是酶和反应的新手,所以不知道我是否正确地做了。感谢所有帮助。