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

Extracting an expectation group function

The three expectations in this test will be needed every time we define a new text field. A simple way to avoid repeating each expectation is to extract an arrow function that runs all three as a group:

const expectToBeInputFieldOfTypeText = formElement => {
expect(formElement).not.toBeNull();
expect(formElement.tagName).toEqual('INPUT');
expect(formElement.type).toEqual('text');
};

Define this function above your test and replace the expectations in your test with a call to this function.

In the next chapter, we'll build a Jest matcher that performs a similar function, but for a different use case.
主站蜘蛛池模板: 田林县| 喜德县| 岑溪市| 汝阳县| 遂平县| 永州市| 成武县| 武夷山市| 淳安县| 微博| 马关县| 桂阳县| 道真| 湘阴县| 响水县| 洛扎县| 乌拉特中旗| 额济纳旗| 长沙县| 阿鲁科尔沁旗| 昭平县| 工布江达县| 额尔古纳市| 方城县| 报价| 青州市| 霍城县| 大连市| 连云港市| 弋阳县| 云和县| 定陶县| 南靖县| 永州市| 瓦房店市| 永城市| 永安市| 兴宁市| 林州市| 怀仁县| 温泉县|