May 2019
Intermediate to advanced
496 pages
10h 38m
English
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.
Read now
Unlock full access