The Git tag for this section is extracting-helpers. It contains solutions to the exercises from the previous chapter, so if you haven't completed the Exercises section yourself, then you should move to this tag now so that you're up to date.
For more detailed instructions, see the To get the most out of this book section in the Preface.
For more detailed instructions, see the To get the most out of this book section in the Preface.
In the first chapter, our test suites shared common code for constructing a DOM container element before each test. This element was used as the React root element. By doing this for each test, we avoided modifying global state. Let's extract that code so that we can re-use it across all of our test suites.
The shared code can be split into four parts:
- A common declaration of container in the describe block, accessible by all tests
- A beforeEach call to set container to a newly constructed container element...