Skip to content

Commit

Permalink
test(modify major logic): 상태에서 클래스로 변경된 전공을 관리하는 방법을 테스트 코드에 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
hwinkr committed Jan 6, 2024
1 parent 4663f57 commit 9fa8357
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
12 changes: 4 additions & 8 deletions src/components/Card/InformCard/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import MajorContext from '@contexts/major';
import useModals from '@hooks/useModals';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import Major from '@type/major';
import { IconKind } from '@type/styles/icon';
import { act } from 'react-dom/test-utils';
import { MemoryRouter } from 'react-router-dom';
Expand Down Expand Up @@ -38,18 +37,14 @@ const INFORM_CARD: INFORM_CARD_DATA = {
};

const setMajorMock = (isRender: boolean) => {
const mockMajor: Major = isRender ? null : '컴퓨터인공지능학부';
const mockGetMajor = jest.fn();
const mockSetMajor = jest.fn();

jest.mock('react', () => ({
...jest.requireActual('react'),
useState: () => [mockMajor, mockSetMajor, graduationLink],
}));
mockGetMajor.mockReturnValue(isRender ? null : '컴퓨터인공지능학부');

return {
major: mockMajor,
getMajor: mockGetMajor,
setMajor: mockSetMajor,
graduationLink,
};
};

Expand All @@ -76,6 +71,7 @@ jest.mock('@hooks/useModals', () => {

describe('InformCard 컴포넌트 테스트', () => {
const oldWindowLocation = window.location;

beforeEach(() => {
Object.defineProperty(window, 'location', {
configurable: true,
Expand Down
3 changes: 2 additions & 1 deletion src/pages/MajorDecision/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jest.mock('react-router-dom', () => ({
}));

describe.skip('학과선택 페이지 로직 테스트', () => {
const mockGetMajor = jest.fn();
const mockSetMajor = jest.fn();

beforeEach(() => {
Expand All @@ -33,7 +34,7 @@ describe.skip('학과선택 페이지 로직 테스트', () => {
<MemoryRouter>
<MajorContext.Provider
value={{
major: null,
getMajor: mockGetMajor,
setMajor: mockSetMajor,
}}
>
Expand Down

0 comments on commit 9fa8357

Please sign in to comment.