- Mastering React Test:Driven Development
- Daniel Irvine
- 265字
- 2021-06-24 14:45:10
Nesting describe blocks
We can nest describe blocks to break similar tests up into logical contexts. We can invent our own convention for how to name these describe blocks. Whereas the top level is named after the form itself, the second-level describe blocks are named after the form fields.
Here's how we'd like them to end up:
describe('CustomerForm', () => {
describe('first name field', () => {
// ... tests ...
};
describe('last name field', () => {
// ... tests ...
};
describe('phone number field', () => {
// ... tests ...
};
});
With this structure in place, you can simplify the it descriptive text by removing the name of the field. For example, 'renders the first name field as a text box' becomes 'renders as a text box', because it has already been scoped by the 'first name field' describe block. Because of the way Jest displays describe block names before test names in test output, each of these still reads like a plain-English sentence, but without the verbiage. In the example just given, Jest will show us: CustomerForm first name field renders as a text box.
Let's do that now for the first name field. Wrap the six existing tests in a describe block, and then rename the tests, as shown:
describe('first name field', () => {
it('renders as a text box' ... );
it('includes the existing value' ... );
it('renders a label' ... );
it('assigns an id that matches the label id' ... );
it('saves existing value when submitted' ... );
it('saves new value when submitted' ... );
});
- JSP網(wǎng)絡(luò)編程(學(xué)習(xí)筆記)
- Git高手之路
- oreilly精品圖書:軟件開發(fā)者路線圖叢書(共8冊)
- PHP網(wǎng)絡(luò)編程學(xué)習(xí)筆記
- Learning ELK Stack
- PLC編程與調(diào)試技術(shù)(松下系列)
- Swift細致入門與最佳實踐
- 數(shù)據(jù)結(jié)構(gòu)習(xí)題解析與實驗指導(dǎo)
- C語言程序設(shè)計
- Terraform:多云、混合云環(huán)境下實現(xiàn)基礎(chǔ)設(shè)施即代碼(第2版)
- Vue.js應(yīng)用測試
- Hacking Android
- Python網(wǎng)絡(luò)爬蟲實例教程(視頻講解版)
- Getting Started with the Lazarus IDE
- 讀故事學(xué)編程:Python王國歷險記