From 9c6e849d1c28fc5d475ea2b95af94a501deb9f52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Mon, 21 Mar 2022 09:37:46 +0100 Subject: [PATCH] make the act() expecting test more robust to variations, and fix missing await MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .../test-utils/src/testUtils/appWrappers.test.tsx | 13 ++++++------- .../xcmetrics/src/components/Trend/Trend.test.tsx | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/test-utils/src/testUtils/appWrappers.test.tsx b/packages/test-utils/src/testUtils/appWrappers.test.tsx index 39e5da3df2..32ca3dfc02 100644 --- a/packages/test-utils/src/testUtils/appWrappers.test.tsx +++ b/packages/test-utils/src/testUtils/appWrappers.test.tsx @@ -48,14 +48,13 @@ describe('wrapInTestApp', () => { await Promise.resolve(); }); - expect(error).toEqual([ - expect.stringMatching( - /^Warning: An update to %s inside a test was not wrapped in act\(...\)/, + expect( + error.some(e => + e.includes( + 'Warning: An update to %s inside a test was not wrapped in act(...)', + ), ), - expect.stringMatching( - /^Warning: An update to %s inside a test was not wrapped in act\(...\)/, - ), - ]); + ).toBeTruthy(); }); it('should render a component in a test app without warning about missing act()', async () => { diff --git a/plugins/xcmetrics/src/components/Trend/Trend.test.tsx b/plugins/xcmetrics/src/components/Trend/Trend.test.tsx index 90981e5401..07085150a5 100644 --- a/plugins/xcmetrics/src/components/Trend/Trend.test.tsx +++ b/plugins/xcmetrics/src/components/Trend/Trend.test.tsx @@ -24,7 +24,7 @@ describe('Trend', () => { const rendered = await renderInTestApp( , ); - expect(rendered.findAllByText('testTitle')).toBeTruthy(); + expect(await rendered.findAllByText('testTitle')).toBeTruthy(); }); it('should render empty state', async () => { @@ -32,6 +32,6 @@ describe('Trend', () => { const rendered = await renderInTestApp( , ); - expect(rendered.findAllByText('testTitle')).toBeTruthy(); + expect(await rendered.findAllByText('testTitle')).toBeTruthy(); }); });