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

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.

主站蜘蛛池模板: 南汇区| 高唐县| 邮箱| 曲阜市| 湘潭县| 当阳市| 荣成市| 莲花县| 杭锦后旗| 湾仔区| 松潘县| 婺源县| 景东| 将乐县| 佛学| 叙永县| 曲松县| 桦川县| 吴忠市| 佳木斯市| 四会市| 通道| 鹤壁市| 易门县| 霍林郭勒市| 商洛市| 正定县| 松溪县| 洛阳市| 田东县| 阿克陶县| 三台县| 嘉义市| 海淀区| 大荔县| 吴忠市| 昭通市| 柳州市| 防城港市| 乡城县| 武穴市|