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

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.
主站蜘蛛池模板: 南川市| 长阳| 邢台县| 安远县| 新沂市| 手机| 英德市| 潢川县| 青浦区| 辽宁省| 轮台县| 若尔盖县| 广丰县| 抚顺市| 新宁县| 闻喜县| 遂平县| 乌鲁木齐县| 宜州市| 古浪县| 西盟| 东乌珠穆沁旗| 麻栗坡县| 含山县| 南宁市| 金塔县| 志丹县| 饶阳县| 武乡县| 乌苏市| 永宁县| 卢龙县| 乌拉特前旗| 夏邑县| 涟水县| 安图县| 拉孜县| 江油市| 涟源市| 康保县| 平阳县|