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

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.

主站蜘蛛池模板: 屯门区| 舒兰市| 望都县| 平利县| 嘉峪关市| 北碚区| 鹤山市| 莱西市| 翁牛特旗| 高清| 隆昌县| 浮山县| 卓尼县| 罗山县| 武安市| 佛山市| 普兰县| 无锡市| 安宁市| 榆树市| 赣州市| 曲麻莱县| 象山县| 奈曼旗| 安阳市| 邵东县| 博白县| 会宁县| 七台河市| 襄樊市| 汝南县| 广安市| 股票| 昔阳县| 保德县| 阳原县| 盐池县| 南江县| 光山县| 澳门| 涞水县|