# React 테스트 (React / Next.js) > React Testing Library, Jest, Vitest, 컴포넌트 테스트, mocking, 사용자 인터랙션, coverage - 20 면접 질문 - Mid-Level - [면접 질문: React / Next.js](https://sharpskill.dev/ko/technologies/react-next/interview-questions.md) ## 1. React Testing Library에서 getBy, queryBy, findBy의 주요 차이점은 무엇인가요? **답변** getBy는 요소가 존재하지 않으면 에러를 던집니다(동기적 assertions). queryBy는 요소가 존재하지 않으면 null을 반환합니다(부재 확인). findBy는 비동기 요소를 위해 Promise를 반환합니다. 반드시 존재해야 하는 요소에는 기본적으로 getBy를, 요소가 존재하지 않는지 확인할 때는 queryBy를, 지연 후 요소가 나타나기를 기다릴 때는 findBy를 사용하세요. ## 2. getByTestId에 비해 getByRole의 주요 장점은 무엇인가요? **답변** getByRole은 시맨틱 ARIA role(button, textbox, heading)로 요소를 대상으로 하여 접근성 모범 사례를 장려하며, 스크린 리더를 위한 컴포넌트 접근성을 향상시킵니다. getByTestId는 최종 사용자에게 가치를 제공하지 않는 인위적인 data-testid 속성을 추가해야 합니다. React Testing Library는 getByTestId보다 getByRole, getByLabelText, getByText를 우선 사용할 것을 권장합니다. ## 3. DOM에 존재하지 않는 요소의 조건부 렌더링을 어떻게 테스트하나요? **답변** queryBy를 사용하여 요소의 부재를 확인하세요. 에러를 던지는 대신 null을 반환하기 때문입니다. 예시: expect(screen.queryByText('Error')).toBeNull() 또는 expect(screen.queryByText('Error')).not.toBeInTheDocument(). getBy는 에러를 던져 테스트를 실패시키고, findBy는 요소가 나타나기를 기다립니다(부재 시 timeout). ## 17개 추가 질문 이용 가능 - React Testing Library가 구현 세부 사항을 테스트하지 않도록 권장하는 이유는 무엇인가요? - React Testing Library에서 render와 screen의 차이점은 무엇인가요? 무료로 가입하기: https://sharpskill.dev/ko/login ## 기타 React / Next.js 면접 주제 - [JavaScript 기초](https://sharpskill.dev/ko/technologies/react-next/interview-questions/javascript-essentials.md): 25개 질문, Junior - [React 기초](https://sharpskill.dev/ko/technologies/react-next/interview-questions/react-fundamentals.md): 20개 질문, Junior - [React Hooks](https://sharpskill.dev/ko/technologies/react-next/interview-questions/react-hooks.md): 22개 질문, Junior - [컴포넌트 라이프사이클](https://sharpskill.dev/ko/technologies/react-next/interview-questions/component-lifecycle.md): 18개 질문, Junior - [React Router](https://sharpskill.dev/ko/technologies/react-next/interview-questions/react-router.md): 20개 질문, Junior - [Context를 활용한 상태 관리](https://sharpskill.dev/ko/technologies/react-next/interview-questions/state-management-context.md): 18개 질문, Junior - [폼과 Controlled Components](https://sharpskill.dev/ko/technologies/react-next/interview-questions/forms-controlled-components.md): 20개 질문, Mid-Level - [데이터 가져오기 및 API](https://sharpskill.dev/ko/technologies/react-next/interview-questions/fetching-data-api.md): 20개 질문, Mid-Level - [React Query (TanStack Query)](https://sharpskill.dev/ko/technologies/react-next/interview-questions/react-query-tanstack.md): 20개 질문, Mid-Level - [Styling & CSS-in-JS](https://sharpskill.dev/ko/technologies/react-next/interview-questions/styling-css-in-js.md): 18개 질문, Mid-Level - [Next.js 기초](https://sharpskill.dev/ko/technologies/react-next/interview-questions/nextjs-fundamentals.md): 25개 질문, Mid-Level - [TypeScript와 React](https://sharpskill.dev/ko/technologies/react-next/interview-questions/typescript-react.md): 20개 질문, Mid-Level - [Next.js 데이터 페칭](https://sharpskill.dev/ko/technologies/react-next/interview-questions/nextjs-data-fetching.md): 24개 질문, Mid-Level - [Next.js Server Actions](https://sharpskill.dev/ko/technologies/react-next/interview-questions/nextjs-server-actions.md): 20개 질문, Mid-Level - [Next.js 라우팅 및 내비게이션](https://sharpskill.dev/ko/technologies/react-next/interview-questions/nextjs-routing-navigation.md): 22개 질문, Mid-Level - [Next.js API Routes](https://sharpskill.dev/ko/technologies/react-next/interview-questions/nextjs-api-routes.md): 20개 질문, Mid-Level - [Next.js Metadata & SEO](https://sharpskill.dev/ko/technologies/react-next/interview-questions/nextjs-metadata-seo.md): 18개 질문, Mid-Level - [Next.js Middleware 및 Auth](https://sharpskill.dev/ko/technologies/react-next/interview-questions/nextjs-middleware-auth.md): 22개 질문, Mid-Level - [Zustand State Management](https://sharpskill.dev/ko/technologies/react-next/interview-questions/zustand-state-management.md): 18개 질문, Mid-Level - [React 성능 최적화](https://sharpskill.dev/ko/technologies/react-next/interview-questions/react-performance-optimization.md): 22개 질문, Senior - [Error Boundaries & 에러 핸들링](https://sharpskill.dev/ko/technologies/react-next/interview-questions/react-error-boundaries.md): 18개 질문, Senior - [Advanced React Patterns](https://sharpskill.dev/ko/technologies/react-next/interview-questions/advanced-react-patterns.md): 20개 질문, Senior - [Next.js 고급 기능](https://sharpskill.dev/ko/technologies/react-next/interview-questions/nextjs-advanced-features.md): 24개 질문, Senior - [Next.js 배포 및 프로덕션](https://sharpskill.dev/ko/technologies/react-next/interview-questions/nextjs-deployment-production.md): 20개 질문, Senior - [아키텍처 & 디자인 패턴](https://sharpskill.dev/ko/technologies/react-next/interview-questions/react-architecture-patterns.md): 22개 질문, Senior - [React Server Components](https://sharpskill.dev/ko/technologies/react-next/interview-questions/react-server-components.md): 26개 질문, Senior - [Next.js 국제화](https://sharpskill.dev/ko/technologies/react-next/interview-questions/nextjs-internationalization.md): 20개 질문, Senior - [React 보안 & 모범 사례](https://sharpskill.dev/ko/technologies/react-next/interview-questions/react-security-best-practices.md): 22개 질문, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/ko/technologies/react-next/interview-questions/react-testing