- 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 3移動Web開發與性能調優實戰
- Spring 5.0 Microservices(Second Edition)
- Java FX應用開發教程
- C程序設計案例教程
- SQL Server數據庫管理與開發兵書
- Swift 4 Protocol-Oriented Programming(Third Edition)
- 深入淺出Go語言編程
- JavaScript悟道
- Arduino電子設計實戰指南:零基礎篇
- Visual C++從入門到精通(第2版)
- DB2SQL性能調優秘笈
- Spring Web Services 2 Cookbook
- Visual C++程序設計全程指南
- Jenkins 2.x實踐指南
- MATLAB從入門到精通