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

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.
主站蜘蛛池模板: 资源县| 长泰县| 车致| 滨州市| 贺州市| 元朗区| 深州市| 安徽省| 安阳县| 开封市| 东平县| 庐江县| 临海市| 清水河县| 汪清县| 永春县| 马关县| 进贤县| 杂多县| 新源县| 贵港市| 偃师市| 日土县| 嵊州市| 尼木县| 长岭县| 洛隆县| 兰西县| 茶陵县| 化隆| 玛多县| 柞水县| 门头沟区| 确山县| 怀化市| 大足县| 古浪县| 宾川县| 筠连县| 淮滨县| 南召县|