From ff131b5fd33db84ae01d6067a996a50822223ba7 Mon Sep 17 00:00:00 2001 From: yousifalraheem Date: Mon, 4 Apr 2022 15:45:12 +0200 Subject: [PATCH] fix SettingsPage tests Signed-off-by: Yousif Al-Raheem --- .../src/components/SettingsPage.test.tsx | 35 +++++-------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/plugins/user-settings/src/components/SettingsPage.test.tsx b/plugins/user-settings/src/components/SettingsPage.test.tsx index 865d0918e7..01810bcc8e 100644 --- a/plugins/user-settings/src/components/SettingsPage.test.tsx +++ b/plugins/user-settings/src/components/SettingsPage.test.tsx @@ -27,6 +27,10 @@ jest.mock('react-router', () => ({ import { useOutlet } from 'react-router'; describe('', () => { + beforeEach(() => { + (useOutlet as jest.Mock).mockReset(); + }); + it('should render the settings page with 3 tabs', async () => { const { container } = await renderWithEffects( wrapInTestApp(), @@ -38,13 +42,11 @@ describe('', () => { it('should render the settings page with 4 tabs when extra tabs are provided', async () => { const advancedTabRoute = ( - <> - -
Advanced settings
-
- + +
Advanced settings
+
); - (useOutlet as jest.Mock).mockReturnValueOnce(advancedTabRoute); + (useOutlet as jest.Mock).mockReturnValue(advancedTabRoute); const { container } = await renderWithEffects( wrapInTestApp(), ); @@ -53,25 +55,4 @@ describe('', () => { expect(tabs).toHaveLength(4); expect(tabs[3].textContent).toEqual('Advanced'); }); - - it('should throw error if non compliant route is passed to settings routes', async () => { - const advancedTabRoute = ( - <> - -
Advanced settings
-
-
Non compliant element
- - ); - (useOutlet as jest.Mock).mockReturnValueOnce(advancedTabRoute); - let error: Error; - try { - await renderWithEffects(wrapInTestApp()); - } catch (err) { - error = err; - } - expect(error!.message).toEqual( - expect.stringContaining('Invalid element passed'), - ); - }); });