From 44e86fc068d4e9c356d8341537ff3ece91690f0c Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Thu, 2 May 2024 15:03:49 +0200 Subject: [PATCH] chore: fix failing test; don't rely on a single item only (#6974) This test is breaking right now because it tests a date picker, week 21 is approaching, and `findByText` only expects a single element. Checking that we have *at least* one element fixes that breakage and I don't think it should cause any issues. Of course, that means that right now, this test would also pass even if the expected button wasn't there, but it would stop passing in about four weeks time. --- .../common/FilterDateItem/FilterDateItem.test.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/frontend/src/component/common/FilterDateItem/FilterDateItem.test.tsx b/frontend/src/component/common/FilterDateItem/FilterDateItem.test.tsx index 8aac741251..866baaa532 100644 --- a/frontend/src/component/common/FilterDateItem/FilterDateItem.test.tsx +++ b/frontend/src/component/common/FilterDateItem/FilterDateItem.test.tsx @@ -55,9 +55,14 @@ describe('FilterDateItem Component', () => { it('renders initial popover when no existing value', async () => { const mockState = null; - const recordedChanges = setup(mockState); + setup(mockState); - await screen.findByText('21'); + const results = await screen.findAllByText('21'); + + // In *most* cases, this will probably only be 1, but it *can* + // be more if it's the right time of year (that is: if it + // would also show "week 21"). + expect(results.length).toBeGreaterThanOrEqual(1); }); it('switches operator', async () => {