diff --git a/jest.config.js b/jest.config.js index 65ddb8a..f3d0a53 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,7 +1,8 @@ /* eslint-disable no-undef */ module.exports = { moduleNameMapper: { - '^@/(.*)$': '/src/$1' // '@' 접두사를 'src' 디렉토리로 매핑 + '^@/(.*)$': '/src/$1', // '@' 접두사를 'src' 디렉토리로 매핑 + '^@utils/(.*)$': '/src/utils/$1' }, testPathIgnorePatterns: ['/.next/', '/node_modules/'], setupFilesAfterEnv: ['/jest.setup.js'], diff --git a/src/components/layout/footer/Footer.test.tsx b/src/components/layout/footer/Footer.test.tsx new file mode 100644 index 0000000..2354d2e --- /dev/null +++ b/src/components/layout/footer/Footer.test.tsx @@ -0,0 +1,58 @@ +import { render, screen, fireEvent } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import Footer from '@/components/layout/footer/Footer'; +import { useRouter } from 'next/navigation'; +import { usePathname } from 'next/navigation'; + +jest.mock('next/navigation', () => ({ + useRouter: jest.fn(), + usePathname: jest.fn() +})); + +describe('Footer 컴포넌트', () => { + const pushMock = jest.fn(); + beforeEach(() => { + (useRouter as jest.Mock).mockImplementation(() => ({ + push: pushMock + })); + (usePathname as jest.Mock).mockImplementation(() => '/'); // 기본 경로를 '/'로 설정 + sessionStorage.clear(); + jest.clearAllMocks(); + }); + + test('정상적으로 렌더링되는지 확인', () => { + render(