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

Extracting a form-finder method

We'll be writing quite a few tests for this form, so let's extract the call to querySelector into an arrow function. Add this just below the beforeEach definition:

const form = id => container.querySelector(`form[id="${id}"]`);

The expectation in your test then becomes this:

expect(form('customer')).not.toBeNull();

This is much more readable, because the CSS selector is abstracted away behind the function call. I'd encourage you to repeat that pattern in your tests. CSS selectors are a useful tool, but they detract from the "plain English" that you should be aiming for in your tests.

主站蜘蛛池模板: 武川县| 丹江口市| 芦山县| 芜湖市| 中山市| 湄潭县| 馆陶县| 姜堰市| 印江| 敦煌市| 合水县| 和平县| 宿州市| 永登县| 漯河市| 巴楚县| 嵊泗县| 高平市| 琼海市| 香港| 靖边县| 阳信县| 乐至县| 肥城市| 霍州市| 龙川县| 沾益县| 香河县| 闸北区| 汨罗市| 柳江县| 民丰县| 锡林郭勒盟| 烟台市| 宝鸡市| 格尔木市| 曲周县| 怀来县| 桃园县| 苗栗市| 阜宁县|