From e91f097009d6aa30a26b63a175add479214bebfb Mon Sep 17 00:00:00 2001 From: vetalcore Date: Tue, 26 Nov 2024 14:26:58 +0200 Subject: [PATCH] refactor(common): fix unit tests --- .../CollapsablePanel/__tests__/CollapsablePanel.test.tsx | 2 +- .../components/Drawer/__tests__/DrawerNavigation.test.tsx | 4 ++-- .../src/ui/components/Form/Input/__tests__/Input.test.tsx | 2 +- .../components/Form/TextArea/__tests__/TextArea.test.tsx | 5 +++-- .../src/ui/components/Search/__tests__/Search.test.tsx | 8 +++++--- .../src/ui/components/Toast/__tests__/Toast.test.tsx | 5 +++-- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/common/src/ui/components/CollapsablePanel/__tests__/CollapsablePanel.test.tsx b/packages/common/src/ui/components/CollapsablePanel/__tests__/CollapsablePanel.test.tsx index e07a218f83..596bd718ec 100644 --- a/packages/common/src/ui/components/CollapsablePanel/__tests__/CollapsablePanel.test.tsx +++ b/packages/common/src/ui/components/CollapsablePanel/__tests__/CollapsablePanel.test.tsx @@ -22,7 +22,7 @@ describe('CollapsablePanel', () => { ); const clickable = queryByRole('button'); act(() => { - fireEvent.click(clickable); + clickable && fireEvent.click(clickable); }); expect(queryByTestId('test-content')).toBeInTheDocument(); }); diff --git a/packages/common/src/ui/components/Drawer/__tests__/DrawerNavigation.test.tsx b/packages/common/src/ui/components/Drawer/__tests__/DrawerNavigation.test.tsx index c36f910368..3918a03c4b 100644 --- a/packages/common/src/ui/components/Drawer/__tests__/DrawerNavigation.test.tsx +++ b/packages/common/src/ui/components/Drawer/__tests__/DrawerNavigation.test.tsx @@ -15,7 +15,7 @@ describe('DrawerNavigation', () => { const { queryByTestId } = render(); const backButton = queryByTestId('navigation-button-arrow'); expect(backButton).toBeInTheDocument(); - fireEvent.click(backButton); + backButton && fireEvent.click(backButton); expect(onClick).toHaveBeenCalled(); }); test('shows close button if on click function is defined', () => { @@ -23,7 +23,7 @@ describe('DrawerNavigation', () => { const { queryByTestId } = render(); const closeButton = queryByTestId('navigation-button-cross'); expect(closeButton).toBeInTheDocument(); - fireEvent.click(closeButton); + closeButton && fireEvent.click(closeButton); expect(onClick).toHaveBeenCalled(); }); test('shows left actions if passed as props instead of back arrow', () => { diff --git a/packages/common/src/ui/components/Form/Input/__tests__/Input.test.tsx b/packages/common/src/ui/components/Form/Input/__tests__/Input.test.tsx index e9729638c6..060a0c4a48 100644 --- a/packages/common/src/ui/components/Form/Input/__tests__/Input.test.tsx +++ b/packages/common/src/ui/components/Form/Input/__tests__/Input.test.tsx @@ -15,7 +15,7 @@ describe('Input', () => { const input = queryByTestId('input-test'); expect(input).toHaveValue(''); act(() => { - fireEvent.change(input, { target: { value: 'new value' } }); + input && fireEvent.change(input, { target: { value: 'new value' } }); }); expect(input).toHaveValue('new value'); expect(onChange).toHaveBeenCalled(); diff --git a/packages/common/src/ui/components/Form/TextArea/__tests__/TextArea.test.tsx b/packages/common/src/ui/components/Form/TextArea/__tests__/TextArea.test.tsx index bc17123d73..6bc72eb5a0 100644 --- a/packages/common/src/ui/components/Form/TextArea/__tests__/TextArea.test.tsx +++ b/packages/common/src/ui/components/Form/TextArea/__tests__/TextArea.test.tsx @@ -15,7 +15,7 @@ describe('TextArea', () => { const area = queryByTestId('text-area-test'); expect(area).toHaveValue(''); act(() => { - fireEvent.change(area, { target: { value: 'new value' } }); + area && fireEvent.change(area, { target: { value: 'new value' } }); }); expect(area).toHaveValue('new value'); expect(onChange).toHaveBeenCalled(); @@ -24,7 +24,8 @@ describe('TextArea', () => { const onBlur = jest.fn(); const { queryByTestId } = render(