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

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.
主站蜘蛛池模板: 桑植县| 长乐市| 屯门区| 浪卡子县| 精河县| 海盐县| 通州区| 丰县| 衡南县| 安新县| 海门市| 汝阳县| 涪陵区| 梁河县| 疏附县| 彰武县| 安义县| 虞城县| 大丰市| 周口市| 靖江市| 科技| 满城县| 崇文区| 兴仁县| 毕节市| 玉树县| 蓝山县| 连城县| 诸暨市| 泾川县| 新邵县| 江城| 饶平县| 胶南市| 金秀| 遂宁市| 禄丰县| 萨嘎县| 胶南市| 特克斯县|