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

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.
主站蜘蛛池模板: 正定县| 裕民县| 长治县| 濉溪县| 樟树市| 信丰县| 永吉县| 依兰县| 张家港市| 罗田县| 韶关市| 安岳县| 宜兰县| 石河子市| 玛沁县| 上犹县| 上蔡县| 汨罗市| 常宁市| 儋州市| 罗定市| 肥西县| 安西县| 新乡市| 且末县| 丹江口市| 读书| 施秉县| 彰武县| 中山市| 株洲县| 宜兰县| 闸北区| 大新县| 阜康市| 南昌县| 沅江市| 彭山县| 乌兰察布市| 平山县| 漳浦县|