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

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.

主站蜘蛛池模板: 永清县| 句容市| 汾阳市| 南江县| 鹤岗市| 凭祥市| 万年县| 中西区| 武安市| 灌云县| 海城市| 怀宁县| 浦北县| 雷山县| 滕州市| 卢湾区| 雷山县| 玉环县| 巨野县| 平顶山市| 波密县| 宁远县| 炉霍县| 广西| 马龙县| 怀安县| 泰宁县| 浑源县| 策勒县| 兴仁县| 乌鲁木齐市| 呈贡县| 武安市| 银川市| 灌南县| 犍为县| 灵石县| 哈尔滨市| 富平县| 巫山县| 凤冈县|