This is the child article of ReactTestUtils - Tutorial. In this article, I will explain how to Verify Function Calls with examples.
Example
Here we pass clickFunc and dblClickFunc as properties, now we have to check whether these functions were called or not.
import React from 'react'; class FuncComponent extends React.Component { constructor(props) { super(props); this.dblClickEventFunc = this.dblClickEventFunc.bind(this); } dblClickEventFunc() { this.props.dblClickFunc('this is some sample arg value'); } render () { return <div> <div id="clickEventDiv" onClick={this.props.clickFunc}> </div> <div id="dblClickEventDiv" onDoubleClick={this.dblClickEventFunc}> </div> </div>; } } FuncComponent.propTypes = { clickFunc:React.PropTypes.func, dblClickFunc:React.PropTypes.func } FuncComponent.defaultProps = { } export default FuncComponent;
Verify Function Call
Here done callback has to be called at end of the test. Whenever you simulate the click event, clickFunction will be called. clickFunction will call done callback function, so the test will end with success message
it('function call on click test', (done) => { let clickFunction = () => { done(); }; let instance = ReactTestUtils.renderIntoDocument( <FuncComponent clickFunc={clickFunction}/> ); let clickDiv = scryRenderedDOMComponentsWithId(instance, "clickEventDiv"); ReactTestUtils.Simulate.click(clickDiv[0]); });
Verify Function Argument
Whenever you simulate double click event, dblClickFunction will be called with argument. Here we are checking that argument value in dblClickFunction, then calling done callback function.
it('function argument verification on double click test', (done) => { let dblClickFunction = (arg) => { expect(arg).toEqual('this is some sample arg value'); done(); }; let instance = ReactTestUtils.renderIntoDocument( <FuncComponent dblClickFunc={dblClickFunction}/> ); let clickDiv = scryRenderedDOMComponentsWithId(instance, "dblClickEventDiv"); ReactTestUtils.Simulate.doubleClick(clickDiv[0]); });
PLC Training in Chennai | PLC Training Institute in Chennai | PLC Training Center in Chennai | PLC SCADA Training in Chennai | PLC SCADA DCS Training in Chennai | Best PLC Training in Chennai | Best PLC Training Institute in Chennai | PLC Training Centre in Chennai | Embedded System Training in Chennai | Embedded Training in Chennai | VLSI Training in Chennai | VLSI Training Institute in Chennai
ReplyDeleteIEEE Final Year Project centers make amazing deep learning final year projects ideas for final year students Final Year Projects for CSE to training and develop their deep learning experience and talents.
DeleteIEEE Final Year projects Project Centers in India are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation.
corporate training in chennai corporate training in chennai
corporate training companies in india corporate training companies in india
corporate training companies in chennai corporate training companies in chennai
I have read your blog its very attractive and impressive. I like it your blog. Digital Marketing Company in Chennai Project Centers in Chennai
PLC Training in Chennai | PLC Training Institute in Chennai | PLC Training Center in Chennai | PLC SCADA Training in Chennai | PLC SCADA DCS Training in Chennai | Best PLC Training in Chennai | Best PLC Training Institute in Chennai | PLC Training Centre in Chennai | PLC SCADA Training in Chennai | Automation Training Institute in Chennai | PLC Training in Kerala | VLSI Training in Chennai | Best VLSI Training in Chennai | VLSI Training Centres in Chennai | VLSI Courses in Chennai | VLSI Training Courses in Chennai | VLSI Training Institute in Chennai | VLSI Training Institutes in Chennai | Best VLSI Training Institute in Chennai
ReplyDeleteEmbedded Training in Chennai | Best Embedded Training in Chennai | Embedded System Training in Chennai | Embedded System Training Institute in Chennai | Best Embedded System Training Institute in Chennai | Embedded Course in Chennai | Embedded System Training Institutes in Chennai | Embedded System Training Center in Chennai | Best Embedded System Training in Chennai | Embedded Systems Training in Chennai | VLSI Training in Chennai | VLSI Training Institute in Chennai
ReplyDeleteAmazing Article, Really useful information to all So, I hope you will share more information to be check and share here.
ReplyDeleteJupyter Notebook
Jupyter Notebook Online
Jupyter Notebook Install
Automation Anywhere Tutorial
Rpa automation anywhere tutorial pdf
Automation anywhere Tutorial for beginners
Kivy Python
Kivy Tutorial
Kivy for Python
Kivy Installation on Windows
This was an terrific post. Thanks for providing these details.
ReplyDeletebuy logo design
I am very happy after visiting your website with very useful information. I am from one of the digital marketing agency... To visit my agency click on link Visitdigitalguru
ReplyDeleteHEY!
ReplyDeleteIt's very amazing post, thanks for sharing it with us.
law dissertation Writers