- Mastering React Test:Driven Development
- Daniel Irvine
- 92字
- 2021-06-24 14:45:08
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.
推薦閱讀
- Vue.js設(shè)計(jì)與實(shí)現(xiàn)
- DBA攻堅(jiān)指南:左手Oracle,右手MySQL
- 騰訊iOS測(cè)試實(shí)踐
- NumPy Essentials
- Getting Started with NativeScript
- Scientific Computing with Scala
- Learning Raspbian
- Jenkins Continuous Integration Cookbook(Second Edition)
- C語(yǔ)言程序設(shè)計(jì)
- 微服務(wù)從小白到專家:Spring Cloud和Kubernetes實(shí)戰(zhàn)
- 小型編譯器設(shè)計(jì)實(shí)踐
- 軟件測(cè)試綜合技術(shù)
- Arduino機(jī)器人系統(tǒng)設(shè)計(jì)及開(kāi)發(fā)
- Flink核心技術(shù):源碼剖析與特性開(kāi)發(fā)
- Eclipse開(kāi)發(fā)(學(xué)習(xí)筆記)