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

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.
主站蜘蛛池模板: 金塔县| 东乌珠穆沁旗| 台州市| 襄樊市| 互助| 德钦县| 庆阳市| 东宁县| 平山县| 阿鲁科尔沁旗| 沾益县| 军事| 古丈县| 郎溪县| 上林县| 合水县| 顺平县| 黎川县| 梁平县| 静海县| 黄梅县| 山丹县| 大洼县| 雷州市| 开江县| 巴里| 芦山县| 德昌县| 金沙县| 赣榆县| 景东| 昌吉市| 咸丰县| 乌鲁木齐市| 济南市| 临澧县| 醴陵市| 江达县| 旬阳县| 边坝县| 雅江县|