diff options
Diffstat (limited to 'doc/development/testing_guide/frontend_testing.md')
-rw-r--r-- | doc/development/testing_guide/frontend_testing.md | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/doc/development/testing_guide/frontend_testing.md b/doc/development/testing_guide/frontend_testing.md index 56bbcb815d1..87d8d493512 100644 --- a/doc/development/testing_guide/frontend_testing.md +++ b/doc/development/testing_guide/frontend_testing.md @@ -522,7 +522,7 @@ it('waits for an event', () => { ### Ensuring that tests are isolated -Tests are normally architected in a pattern which requires a recurring setup and breakdown of the component under test. This is done by making use of the `beforeEach` and `afterEach` hooks. +Tests are normally architected in a pattern which requires a recurring setup of the component under test. This is often achieved by making use of the `beforeEach` hook. Example @@ -532,16 +532,22 @@ Example beforeEach(() => { wrapper = mount(Component); }); +``` + +With [enableAutoDestroy](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/100389), it is no longer neccessary to manually call `wrapper.destroy()`. +However, some mocks, spies, and fixtures do need to be torn down, and we can leverage the `afterEach` hook. + +Example + +```javascript + let wrapper; afterEach(() => { - wrapper.destroy(); + fakeApollo = null; + store = null; }); ``` -When looking at this initially you'd suspect that the component is setup before each test and then broken down afterwards, providing isolation between tests. - -This is however not entirely true as the `destroy` method does not remove everything which has been mutated on the `wrapper` object. For functional components, destroy only removes the rendered DOM elements from the document. - ### Jest best practices > [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/34209) in GitLab 13.2. |