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

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.

主站蜘蛛池模板: 三江| 洮南市| 兴文县| 延庆县| 上栗县| 如皋市| 四平市| 房山区| 马边| 年辖:市辖区| 张掖市| 武定县| 东方市| 青冈县| 博湖县| 宣恩县| 西乌| 连州市| 辽源市| 黎川县| 扶风县| 望都县| 驻马店市| 宽甸| 苏尼特右旗| 高陵县| 溧水县| 留坝县| 金山区| 襄汾县| 腾冲县| 栾川县| 东安县| 贺兰县| 康平县| 山西省| 弥渡县| 阿图什市| 盖州市| 通许县| 大宁县|