- 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.
推薦閱讀
- 軟件安全技術(shù)
- Manga Studio Ex 5 Cookbook
- 我的第一本算法書
- Selenium Design Patterns and Best Practices
- Podman實(shí)戰(zhàn)
- Python機(jī)器學(xué)習(xí)實(shí)戰(zhàn)
- Apache Spark 2.x for Java Developers
- Getting Started with LLVM Core Libraries
- 利用Python進(jìn)行數(shù)據(jù)分析
- 動手學(xué)數(shù)據(jù)結(jié)構(gòu)與算法
- 區(qū)塊鏈技術(shù)進(jìn)階與實(shí)戰(zhàn)(第2版)
- R語言數(shù)據(jù)可視化:科技圖表繪制
- Getting Started with React VR
- INSTANT LESS CSS Preprocessor How-to
- 微信公眾平臺開發(fā)最佳實(shí)踐