From 1198bda2a207b20e9265496b1e22e79f63a251fa Mon Sep 17 00:00:00 2001 From: Laurence de Bruxelles Date: Tue, 10 Aug 2021 11:21:53 +0100 Subject: [PATCH] Fix test isolation of accordion component tests The unit tests for the accordion component can interfere with each other, because within a test suite Puppeteer browser instances are shared, and the accordion component has state stored in the browser session storage. This is especially a problem for any tests after `it('should maintain the expanded state after a page refresh')`, which leaves all the accordion sections opened. This commit adds a simple teardown function to clear the session storage after each test. It just so happens that our current tests behave the same and still pass with the teardown function, but we should fix this problem now, to prevent any future tests from being affected by the state of our current tests, such as for the accordion design refresh in PR #2257. --- src/govuk/components/accordion/accordion.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/govuk/components/accordion/accordion.test.js b/src/govuk/components/accordion/accordion.test.js index e9b2fc6052..4f2bd43dd0 100644 --- a/src/govuk/components/accordion/accordion.test.js +++ b/src/govuk/components/accordion/accordion.test.js @@ -38,6 +38,11 @@ describe('/components/accordion', () => { }) describe('when JavaScript is available', () => { + afterEach(async () => { + // clear accordion state + await page.evaluate(() => window.sessionStorage.clear()) + }) + it('should indicate that the sections are not expanded', async () => { await page.goto(baseUrl + '/components/accordion/preview', { waitUntil: 'load' })