# React テスト (React / Next.js) > React Testing Library、Jest、Vitest、コンポーネントテスト、mocking、ユーザーインタラクション、coverage - 20 面接問題 - Mid-Level - [面接問題: React / Next.js](https://sharpskill.dev/ja/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 ロール(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 は要素の出現を待ちます(不在の場合はタイムアウト)。 ## さらに17問利用可能 - React Testing Library が実装の詳細をテストしないことを推奨するのはなぜですか? - React Testing Library における render と screen の違いは何ですか? 無料で登録: https://sharpskill.dev/ja/login ## その他のReact / Next.js面接トピック - [JavaScript の基礎](https://sharpskill.dev/ja/technologies/react-next/interview-questions/javascript-essentials.md): 25問, Junior - [React の基礎](https://sharpskill.dev/ja/technologies/react-next/interview-questions/react-fundamentals.md): 20問, Junior - [React Hooks](https://sharpskill.dev/ja/technologies/react-next/interview-questions/react-hooks.md): 22問, Junior - [コンポーネントのライフサイクル](https://sharpskill.dev/ja/technologies/react-next/interview-questions/component-lifecycle.md): 18問, Junior - [React Router](https://sharpskill.dev/ja/technologies/react-next/interview-questions/react-router.md): 20問, Junior - [Contextを使った状態管理](https://sharpskill.dev/ja/technologies/react-next/interview-questions/state-management-context.md): 18問, Junior - [フォームと Controlled Components](https://sharpskill.dev/ja/technologies/react-next/interview-questions/forms-controlled-components.md): 20問, Mid-Level - [データ取得と API](https://sharpskill.dev/ja/technologies/react-next/interview-questions/fetching-data-api.md): 20問, Mid-Level - [React Query (TanStack Query)](https://sharpskill.dev/ja/technologies/react-next/interview-questions/react-query-tanstack.md): 20問, Mid-Level - [Styling & CSS-in-JS](https://sharpskill.dev/ja/technologies/react-next/interview-questions/styling-css-in-js.md): 18問, Mid-Level - [Next.jsの基礎](https://sharpskill.dev/ja/technologies/react-next/interview-questions/nextjs-fundamentals.md): 25問, Mid-Level - [TypeScriptとReact](https://sharpskill.dev/ja/technologies/react-next/interview-questions/typescript-react.md): 20問, Mid-Level - [Next.js データフェッチング](https://sharpskill.dev/ja/technologies/react-next/interview-questions/nextjs-data-fetching.md): 24問, Mid-Level - [Next.js Server Actions](https://sharpskill.dev/ja/technologies/react-next/interview-questions/nextjs-server-actions.md): 20問, Mid-Level - [Next.jsのルーティングとナビゲーション](https://sharpskill.dev/ja/technologies/react-next/interview-questions/nextjs-routing-navigation.md): 22問, Mid-Level - [Next.js API Routes](https://sharpskill.dev/ja/technologies/react-next/interview-questions/nextjs-api-routes.md): 20問, Mid-Level - [Next.js Metadata & SEO](https://sharpskill.dev/ja/technologies/react-next/interview-questions/nextjs-metadata-seo.md): 18問, Mid-Level - [Next.js の Middleware と Auth](https://sharpskill.dev/ja/technologies/react-next/interview-questions/nextjs-middleware-auth.md): 22問, Mid-Level - [Zustand State Management](https://sharpskill.dev/ja/technologies/react-next/interview-questions/zustand-state-management.md): 18問, Mid-Level - [React パフォーマンス最適化](https://sharpskill.dev/ja/technologies/react-next/interview-questions/react-performance-optimization.md): 22問, Senior - [Error Boundaries & エラーハンドリング](https://sharpskill.dev/ja/technologies/react-next/interview-questions/react-error-boundaries.md): 18問, Senior - [Advanced React Patterns](https://sharpskill.dev/ja/technologies/react-next/interview-questions/advanced-react-patterns.md): 20問, Senior - [Next.jsの高度な機能](https://sharpskill.dev/ja/technologies/react-next/interview-questions/nextjs-advanced-features.md): 24問, Senior - [Next.jsのデプロイメントと本番環境](https://sharpskill.dev/ja/technologies/react-next/interview-questions/nextjs-deployment-production.md): 20問, Senior - [アーキテクチャ & デザインパターン](https://sharpskill.dev/ja/technologies/react-next/interview-questions/react-architecture-patterns.md): 22問, Senior - [React Server Components](https://sharpskill.dev/ja/technologies/react-next/interview-questions/react-server-components.md): 26問, Senior - [Next.js の国際化](https://sharpskill.dev/ja/technologies/react-next/interview-questions/nextjs-internationalization.md): 20問, Senior - [React セキュリティ & ベストプラクティス](https://sharpskill.dev/ja/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/ja/technologies/react-next/interview-questions/react-testing