From 85e03932bdb7295ae3b053bbb233f4bad45f275a Mon Sep 17 00:00:00 2001 From: Kim Da Eun Date: Tue, 10 Sep 2024 10:53:59 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=EA=B8=B0=EC=A1=B4=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=8B=A4=ED=8C=A8=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/jest.config.js | 1 + frontend/setupTests.ts | 6 ++++++ .../useDashboardCreateForm.test.tsx | 13 ++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/frontend/jest.config.js b/frontend/jest.config.js index 607b3f794..67c692f16 100644 --- a/frontend/jest.config.js +++ b/frontend/jest.config.js @@ -17,6 +17,7 @@ module.exports = { '^@types/(.*)$': '/src/types/$1', '^@utils/(.*)$': '/src/utils/$1', '^@mocks/(.*)$': '/src/mocks/$1', + '^@router/(.*)$': '/src/router/$1', }, testEnvironmentOptions: { customExportConditions: [''], diff --git a/frontend/setupTests.ts b/frontend/setupTests.ts index 80e794f5c..652f6c236 100644 --- a/frontend/setupTests.ts +++ b/frontend/setupTests.ts @@ -5,10 +5,16 @@ global.React = React; beforeAll(() => { server.listen({ onUnhandledRequest: 'error' }); + + jest.spyOn(Storage.prototype, 'setItem'); + jest.spyOn(Storage.prototype, 'getItem'); + jest.spyOn(Storage.prototype, 'removeItem'); }); afterEach(() => { server.resetHandlers(); + + jest.restoreAllMocks(); }); afterAll(() => { diff --git a/frontend/src/hooks/useDashboardCreateForm/useDashboardCreateForm.test.tsx b/frontend/src/hooks/useDashboardCreateForm/useDashboardCreateForm.test.tsx index 192756c08..52a0da81f 100644 --- a/frontend/src/hooks/useDashboardCreateForm/useDashboardCreateForm.test.tsx +++ b/frontend/src/hooks/useDashboardCreateForm/useDashboardCreateForm.test.tsx @@ -1,14 +1,25 @@ import { PropsWithChildren } from 'react'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { act, renderHook } from '@testing-library/react'; +import ToastProvider from '@contexts/ToastContext'; import useDashboardCreateForm from '.'; describe('useDashboardCreateForm', () => { + beforeAll(() => { + localStorage.setItem('clubId', '1'); + }); + + afterAll(() => { + localStorage.removeItem('clubId'); + }); + const createWrapper = () => { const queryClient = new QueryClient(); // eslint-disable-next-line react/function-component-definition return ({ children }: PropsWithChildren) => ( - {children} + + {children} + ); };