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

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.

主站蜘蛛池模板: 泸州市| 晋城| 弋阳县| 肇源县| 襄垣县| 独山县| 德江县| 恩施市| 如东县| 怀柔区| 保山市| 平顶山市| 武义县| 堆龙德庆县| 隆化县| 上思县| 甘孜| 信丰县| 涪陵区| 隆回县| 汶川县| 皋兰县| 永善县| 崇文区| 金湖县| 张家界市| 寿阳县| 石首市| 辉县市| 宜都市| 新田县| 湛江市| 泸州市| 桂东县| 泾川县| 称多县| 定兴县| 沿河| 白玉县| 长寿区| 南丰县|