Skip to content

親コンポーネントから受け取ったPropsの値が正しく表示されているかのテストを追加 #51

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

Merged
merged 4 commits into from
Mar 16, 2025

Conversation

XeicuLy
Copy link
Owner

@XeicuLy XeicuLy commented Mar 16, 2025

Summary by CodeRabbit

  • 新機能
    • 「Props」ページを新規追加し、親子コンポーネント間でテキストが正しく表示されるようになりました。
    • ホームページに「Props」ページへのナビゲーションリンクを実装し、ユーザーが簡単にアクセスできるようになりました。

XeicuLy added 2 commits March 16, 2025 16:32
親コンポーネントから受け取ったPropsの値が正しく表示されているかのテストを追加

ISSUES CLOSED: #33
@XeicuLy XeicuLy self-assigned this Mar 16, 2025
Copy link

coderabbitai bot commented Mar 16, 2025

Walkthrough

このプルリクエストは、Vue コンポーネントとそれに対するテストの新規実装を行っています。具体的には、ChildComponent.vue が props(text)を受け取り表示する機能を持ち、ParentComponent.vue がその子コンポーネントに値を渡します。また、Vitest を用いたテストファイルで子コンポーネントの表示検証が追加され、ナビゲーションリンクと Props ページの導入も行われています。

Changes

ファイルパス 変更内容
src/__test__/components/props/ChildComponent.nuxt.spec.ts ChildComponent の props 表示を検証するテストファイルを追加
src/components/props/ChildComponent.vue, src/components/props/ParentComponent.vue 新規コンポーネントを追加。ChildComponent は text プロパティを表示し、ParentComponent は ChildComponent に "Hello World" を渡す
src/pages/index.vue, src/pages/props/index.vue ナビゲーションリンクの追加および、ParentComponent をレンダリングする Props ページを作成

Sequence Diagram(s)

sequenceDiagram
    participant P as ParentComponent
    participant C as ChildComponent
    P->>C: "text: 'Hello World'" を渡す
    C-->>P: "Hello World" を表示
Loading
sequenceDiagram
    participant T as Vitest Test
    participant C as ChildComponent
    T->>C: "text: 'Test Props'" でマウント
    C-->>T: "Test Props" を表示
Loading

Assessment against linked issues

Objective Addressed Explanation
親コンポーネントから受け取ったPropsの値が正しく表示されているか (#33)

Possibly related PRs

Poem

わたしは小さなウサギ、コードの野原を駆け抜け
新たなテストとコンポーネントで、心はぴょんぴょん
親から子へと流れる愛、それは props の奇跡
一行ひと行、正しく輝くコードで踊る
ぴょんっ、と跳ねる幸せ、今日もハッピーな更新!

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/__test__/components/props/ChildComponent.nuxt.spec.ts

Oops! Something went wrong! :(

ESLint: 9.22.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@eslint/compat' imported from /eslint.config.mjs
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

src/components/props/ChildComponent.vue

Oops! Something went wrong! :(

ESLint: 9.22.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@eslint/compat' imported from /eslint.config.mjs
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 36f8dc9 and 17b22c5.

📒 Files selected for processing (2)
  • src/__test__/components/props/ChildComponent.nuxt.spec.ts (1 hunks)
  • src/components/props/ChildComponent.vue (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (5)
src/components/props/ChildComponent.vue (2)

1-9: コンポーネントのプロパティ定義が適切に実装されています

TypeScriptを使用して型定義を行い、オプショナルなプロパティに対してデフォルト値を提供する実装は良い実践です。コンポーネントが再利用可能で、親コンポーネントから値が渡されない場合のフォールバック動作も考慮されています。


10-12: テンプレートが単純明快でプロパティ値を適切に表示しています

idセレクタを使用することで、テスト時に要素を特定しやすくなっています。これはテスト可能性を高める良い実践です。

src/__test__/components/props/ChildComponent.nuxt.spec.ts (3)

1-4: テストの設定と依存関係が適切に読み込まれています

Vitestのテストユーティリティとコンポーネント、カスタムヘルパー関数を適切にインポートしています。mountSuspendedComponentを使用することで、非同期コンポーネントのマウント処理を簡略化できています。


5-15: 親コンポーネントから受け取ったプロップスのテストが適切に実装されています

テスト名が明確で、何をテストしているかが分かりやすく記述されています。コンポーネントの存在確認とプロップス値の表示確認の両方をテストしており、基本的な機能検証としては十分です。


17-22: デフォルト値のテストが適切に実装されています

プロップスが渡されない場合のデフォルト動作を確認するテストが追加されています。これはコンポーネントの堅牢性を確保するために重要なテストケースです。


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai bot added the テスト テスト関連 label Mar 16, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f588bb8 and 36f8dc9.

📒 Files selected for processing (5)
  • src/__test__/components/props/ChildComponent.nuxt.spec.ts (1 hunks)
  • src/components/props/ChildComponent.vue (1 hunks)
  • src/components/props/ParentComponent.vue (1 hunks)
  • src/pages/index.vue (1 hunks)
  • src/pages/props/index.vue (1 hunks)
🔇 Additional comments (9)
src/pages/index.vue (1)

6-8: ナビゲーションリンクの追加: 良い実装です!

Propsページへのナビゲーションリンクが適切に追加されています。これにより、ユーザーは新しく実装されたPropsのデモページに簡単にアクセスできるようになります。

src/pages/props/index.vue (1)

1-6: 新規ページの実装: クリーンな構造です

ParentComponentをインポートして表示する新しいページが適切に実装されています。シンプルで理解しやすいコードです。コンポーネントの階層構造(親子関係)も明確になっており、良い設計です。

src/components/props/ParentComponent.vue (1)

1-8: 親コンポーネントの実装: 良い設計です

ChildComponentを適切にインポートし、必要なprops(text)を渡しています。id属性を使用して親コンポーネントを特定できるようにしているのも、テストの観点から良い実装です。

コンポーネント名とファイル名が一致しており、Vue.jsのベストプラクティスに従っています。

src/components/props/ChildComponent.vue (2)

1-7: Propsの型定義: 適切な実装です

TypeScriptを使用してProps型を明示的に定義し、definePropsで型安全に使用している点が素晴らしいです。これにより、プロパティの型チェックが強化され、開発時のエラー検出が容易になります。


8-10: テンプレートの実装: シンプルで効果的です

id属性を使用してコンポーネントを特定できるようにしており、テストの観点から適切です。受け取ったpropsの値が正しく表示されるように実装されています。

この実装は、PRの目的である「親コンポーネントから受け取ったPropsの値が正しく表示されているかのテスト」に適した構造になっています。

src/__test__/components/props/ChildComponent.nuxt.spec.ts (4)

1-4: 適切なインポート文が使用されています

必要なテスト関連のユーティリティと対象コンポーネントを正しくインポートしています。mountSuspendedComponentヘルパー関数の使用は、Nuxtコンポーネントのテストに適切です。


5-7: テスト構造が明確です

テストスイートの構造が明確で、何をテストしているのかが分かりやすくなっています。テスト名も「親コンポーネントから受け取ったPropsの値が適切に表示されるか」と具体的で理解しやすいです。


8-11: プロパティの設定が適切です

テスト用のプロパティ値を明確に定義し、mountSuspendedComponentを使用してコンポーネントをマウントする方法は効果的です。


13-15: テスト検証が明確です

コンポーネントの存在確認と、プロパティ値が正しく表示されているかの確認が適切に行われています。#child-componentセレクタを使用して特定の要素のテキスト内容を検証する方法は効果的です。

@XeicuLy XeicuLy merged commit a1e8a7e into main Mar 16, 2025
8 checks passed
@XeicuLy XeicuLy deleted the feature/add-props-test branch March 16, 2025 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
テスト テスト関連
Projects
None yet
Development

Successfully merging this pull request may close these issues.

親コンポーネントから受け取ったPropsの値が正しく表示されているか
1 participant