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

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.

主站蜘蛛池模板: 黄石市| 高唐县| 内江市| 中阳县| 昆山市| 资阳市| 比如县| 凌云县| 临澧县| 贵南县| 东兴市| 汽车| 达孜县| 德惠市| 乳源| 界首市| 雷山县| 高雄县| 广西| 虞城县| 湖北省| 平潭县| 肇庆市| 桃江县| 松江区| 兴化市| 乌拉特前旗| 屯昌县| 江川县| 偃师市| 修武县| 阳原县| 理塘县| 黑水县| 兴国县| 宁陵县| 阳原县| 龙口市| 渭南市| 松桃| 岱山县|