Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue] jest에서 Icon 컴포넌트를 랜더하지 못하는 이슈 #29

Closed
2 tasks done
L2HYUNN opened this issue Mar 13, 2023 · 0 comments
Closed
2 tasks done
Assignees
Labels
Status: Done 리뷰까지 완료 된 이슈 Type: Bug 유형: 버그

Comments

@L2HYUNN
Copy link
Member

L2HYUNN commented Mar 13, 2023

📣 이슈 내용

  • jest에서 Icon 컴포넌트를 사용하지 못하는 문제가 있습니다.

✏️ 상세 설명

jest에서 Icon 컴포넌트를 사용하지 못하는 문제가 있습니다.

  • 다음의 사진과 같이 Icon 컴포넌트를 랜더하지 못하고 있습니다.
  • jest에서 svg를 컴포넌트로 사용하기 위해 @svgr/webpack를 사용할 때 svg가 기본적으로 매핑되는 방식이 이미지 object 형태이기 때문에 발생하는 문제로 보입니다.
  • 아래의 참고 자료를 해결하여 여러 방법을 시도해보았지만 해결되지 않아 이슈로 남깁니다.

image

시도한 방법

1. SVGR에서 제공하는 Jest 설정 추가

2. vercel/next.js#42535 참고하여 jest.config.js 수정

해결

  • 기존의 jest.cofig.js를 다음과 같이 변경하였습니다.
// 변경 전
/* eslint-disable-next-line @typescript-eslint/no-var-requires */
const nextJest = require('next/jest');

const createJestConfig = nextJest({
  dir: './',
});

const customJestConfig = {
  setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
  moduleNameMapper: {
    '^~/(.*)$': '<rootDir>/src/$1',
    '\\.svg$': '<rootDir>/__mocks__/svg.js',
  },
  testEnvironment: 'jest-environment-jsdom',
  testPathIgnorePatterns: ['<rootDir>/src/__tests__/utils/*'],
};

module.exports = createJestConfig(customJestConfig);
// 변경 후
/* eslint-disable @typescript-eslint/no-var-requires */
const nextJest = require('next/jest');

const createJestConfig = nextJest({
  dir: './',
});

const jestConfig = async () => {
  const nextJestConfig = await createJestConfig()();
  return {
    ...nextJestConfig,
    setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
    testEnvironment: 'jest-environment-jsdom',
    moduleNameMapper: {
      '^~/(.*)$': '<rootDir>/src/$1',
      '\\.svg$': '<rootDir>/__mocks__/svg.js',
    },
    testPathIgnorePatterns: ['<rootDir>/src/__tests__/utils/*'],
  };
};

module.exports = jestConfig;

image

🧑🏻‍💻 할 일

  • jest에서 발생하는 svg 문제 해결하기
  • 시도한 방법 업데이트하기

📁 참고 자료

@L2HYUNN L2HYUNN self-assigned this Mar 13, 2023
@L2HYUNN L2HYUNN added Type: Bug 유형: 버그 Priority: High 우선순위: 상 Status: To Do 처리해야 되는 이슈 Status: In Progress 현재 처리 중인 이슈 Status: Reviewing 처리하고 리뷰 중인 이슈 and removed Status: To Do 처리해야 되는 이슈 Status: In Progress 현재 처리 중인 이슈 Priority: High 우선순위: 상 labels Mar 13, 2023
@L2HYUNN L2HYUNN added Status: Done 리뷰까지 완료 된 이슈 and removed Status: Reviewing 처리하고 리뷰 중인 이슈 labels Mar 20, 2023
@L2HYUNN L2HYUNN closed this as completed Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Done 리뷰까지 완료 된 이슈 Type: Bug 유형: 버그
Projects
None yet
Development

No branches or pull requests

1 participant