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

Using a beforeEach block

Both of our tests start with some setup or arrangement. When that setup is common to all tests, we can promote them into a beforeEach block instead. Code in this block is executed before each test.

Above your first test, write the following code, and delete the corresponding call to createElement from each of your two tests:

beforeEach(() => {
container = document.createElement('div');
});

Since we defined container in the scope of the describe block, the value set here in the beforeEach block will be available to our test once it executes.

Be careful when you use variables defined within the describe scope. These variables are not cleared between each test execution, so you are running the risk of non-independent tests. Therefore, any variable you declare in the describe scope should be assigned to a new value in a corresponding beforeEach block, or in the first part of each test, just as we've done here.
主站蜘蛛池模板: 修文县| 阳曲县| 永善县| 桂平市| 岑巩县| 汕尾市| 石渠县| 桃江县| 鄢陵县| 兴城市| 岳普湖县| 井陉县| 江口县| 临邑县| 西乡县| 峨眉山市| 广宁县| 长治县| 理塘县| 兰坪| 丹巴县| 梅州市| 高雄县| 漳平市| 平遥县| 大姚县| 玉溪市| 宣化县| 中西区| 长岭县| 凯里市| 台北县| 获嘉县| 秦安县| 霍林郭勒市| 句容市| 贵南县| 光泽县| 浠水县| 台南市| 长丰县|