官术网_书友最值得收藏!

Extracting methods

The call to ReactDOM.render is the same in both methods. Since it's the same in both methods, it makes sense to pull it out.

However, rather than pull it out as-is, we can create a new function that takes the Appointment component as its parameter. This way, we can clearly see how our test data objects are woven through the object under test. If we hid that within an extracted method, the test would be less clear.

The parts of a test that you want to see are the parts that differ between tests. Usually, some data remains the same ( container in this example) and some differs ( customer in this example). Do your best to hide away whatever is the same and proudly display what differs.

Above the first test, write the following definition:

const render = component => ReactDOM.render(component, container);

Now, replace the call to ReactDOM.render in each test with this line:

render(<Appointment customer={customer} />);

Re-run your tests now—they should still be passing.

主站蜘蛛池模板: 海城市| 双流县| 安义县| 蓬莱市| 彭山县| 扬州市| 南岸区| 固镇县| 松江区| 浙江省| 肃宁县| 德兴市| 财经| 永修县| 饶平县| 张家口市| 浪卡子县| 新河县| 南召县| 梁山县| 永胜县| 台江县| 宁强县| 桂东县| 江川县| 库车县| 包头市| 锡林浩特市| 新巴尔虎左旗| 郯城县| 乌兰察布市| 大悟县| 松溪县| 朝阳市| 蓝田县| 始兴县| 师宗县| 东安县| 米泉市| 青阳县| 滦南县|