Skip to content

🧪 Add tests for ErrorMessages component#325

Open
is0692vs wants to merge 2 commits into
mainfrom
test-errormessages-14649242591864242114
Open

🧪 Add tests for ErrorMessages component#325
is0692vs wants to merge 2 commits into
mainfrom
test-errormessages-14649242591864242114

Conversation

@is0692vs

@is0692vs is0692vs commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

🎯 What: Added missing test file for ErrorMessages.tsx component.
📊 Coverage: Covered edge cases such as undefined errors array, empty arrays, single error, and multiple errors rendering properly. Modified vitest.config.ts to include the new file in test coverage reports.
Result: Test coverage for ErrorMessages.tsx is now 100%. Tests execute correctly verifying component robustness.


PR created automatically by Jules for task 14649242591864242114 started by @is0692vs

Greptile Summary

ErrorMessages.tsx コンポーネントのテストファイルを新規追加し、vitest のカバレッジ設定にも追加したPRです。

  • 4 つのテストケース(undefined・空配列・単一エラー・複数エラー)を追加しているが、{err.message}<strong> の隣にある裸のテキストノードとして描画されるため、screen.getByText('Test message') がマッチする DOM 要素を見つけられず TestingLibraryElementError をスローする。単一エラーと複数エラーの 2 つのテストが現状では失敗する。
  • vitest.config.ts への変更は ErrorMessages.tsx をカバレッジ対象に追加するだけで、問題はない。

Confidence Score: 3/5

テストコードのみの変更であり、プロダクションコードへの影響はないが、テストの中心的なアサーションが実際には失敗するため、このPRが目指す「テスト保護」は現時点では機能していない。

メッセージテキストのアサーションが getByText の完全一致制約により 2 つのテストで失敗する。PR の主目的(テストによるコンポーネント検証)の半数が壊れた状態であり、修正なしにマージすると CI が通らないか、偽のカバレッジ数値を報告する可能性がある。

src/app/[username]/components/ErrorMessages.test.tsx の renders a single error message correctlyrenders multiple error messages correctly の 2 テストケース

Important Files Changed

Filename Overview
src/app/[username]/components/ErrorMessages.test.tsx ErrorMessages コンポーネントの新規テストファイル。undefined・空配列・単一エラー・複数エラーのケースを網羅しているが、getByText でメッセージテキスト(裸のテキストノード)を検索するアサーションが 2 つのテストケースで失敗する。
vitest.config.ts カバレッジ対象ファイルリストに ErrorMessages.tsx を追加。変更は最小限で問題なし。

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[ErrorMessages コンポーネント] --> B{errors が undefined?}
    B -- Yes --> C[null を返す]
    B -- No --> D{errors.length === 0?}
    D -- Yes --> C
    D -- No --> E[エラーリストを描画]
    E --> F["strong: section: /strong + message テキストノード"]

    subgraph テストケース
        T1["✅ Test 1: errors=undefined → null"]
        T2["✅ Test 2: errors=[] → null"]
        T3["❌ Test 3: getByText('Test message') → 要素なし"]
        T4["❌ Test 4: getByText('Message 1') → 要素なし"]
    end

    C --> T1
    C --> T2
    F --> T3
    F --> T4
Loading
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
src/app/[username]/components/ErrorMessages.test.tsx:17-23
`screen.getByText('Test message')` はエラーをスローします。`{err.message}` はコンポーネント内で `<strong>` の隣にある裸のテキストノードとして描画されるため、DOM 要素の `textContent` が完全一致する要素が存在しません(外側の `div``textContent``"Test Section: Test message"` になります)。`getByText` はデフォルトで `exact: true` で動作するため、一致する要素が見つからず `TestingLibraryElementError` がスローされてテストが失敗します。`container.toHaveTextContent` を使うと、コンテナの textContent に文字列が含まれているかを検証できます。

```suggestion
  it('renders a single error message correctly', () => {
    const errors = [{ section: 'Test Section', message: 'Test message' }];
    const { container } = render(<ErrorMessages errors={errors} />);

    expect(screen.getByText('Test Section:')).toBeInTheDocument();
    expect(container).toHaveTextContent('Test message');
  });
```

### Issue 2 of 2
src/app/[username]/components/ErrorMessages.test.tsx:25-36
複数エラーのテストでも同じ問題が発生します。`'Message 1'` / `'Message 2'` はいずれも単独の DOM 要素に紐付かない裸のテキストノードであるため、`getByText` でそれぞれを検索すると `TestingLibraryElementError` がスローされてテストが失敗します。`container.toHaveTextContent` に変更してください。

```suggestion
  it('renders multiple error messages correctly', () => {
    const errors = [
      { section: 'Section 1', message: 'Message 1' },
      { section: 'Section 2', message: 'Message 2' },
    ];
    const { container } = render(<ErrorMessages errors={errors} />);

    expect(screen.getByText('Section 1:')).toBeInTheDocument();
    expect(container).toHaveTextContent('Message 1');
    expect(screen.getByText('Section 2:')).toBeInTheDocument();
    expect(container).toHaveTextContent('Message 2');
  });
```

Reviews (1): Last reviewed commit: "🧪 Add tests for ErrorMessages component" | Re-trigger Greptile

Greptile also left 2 inline comments on this PR.

Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel

vercel Bot commented Jun 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
github-user-summary Ignored Ignored Jun 4, 2026 7:46am

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@is0692vs, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 1 minute and 55 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 719880b0-44eb-4f5d-b871-bd8e093f2363

📥 Commits

Reviewing files that changed from the base of the PR and between f5cfe46 and 0deb75c.

📒 Files selected for processing (2)
  • src/app/[username]/components/ErrorMessages.test.tsx
  • vitest.config.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test-errormessages-14649242591864242114

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a comprehensive test suite in ErrorMessages.test.tsx to verify the behavior of the ErrorMessages component, covering cases with undefined, empty, single, and multiple error messages. Additionally, the ErrorMessages.tsx file is added to the exclusion list in vitest.config.ts. There are no review comments to address, and we have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@codecov

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment on lines +17 to +23
it('renders a single error message correctly', () => {
const errors = [{ section: 'Test Section', message: 'Test message' }];
render(<ErrorMessages errors={errors} />);

expect(screen.getByText('Test Section:')).toBeInTheDocument();
expect(screen.getByText('Test message')).toBeInTheDocument();
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 screen.getByText('Test message') はエラーをスローします。{err.message} はコンポーネント内で <strong> の隣にある裸のテキストノードとして描画されるため、DOM 要素の textContent が完全一致する要素が存在しません(外側の divtextContent"Test Section: Test message" になります)。getByText はデフォルトで exact: true で動作するため、一致する要素が見つからず TestingLibraryElementError がスローされてテストが失敗します。container.toHaveTextContent を使うと、コンテナの textContent に文字列が含まれているかを検証できます。

Suggested change
it('renders a single error message correctly', () => {
const errors = [{ section: 'Test Section', message: 'Test message' }];
render(<ErrorMessages errors={errors} />);
expect(screen.getByText('Test Section:')).toBeInTheDocument();
expect(screen.getByText('Test message')).toBeInTheDocument();
});
it('renders a single error message correctly', () => {
const errors = [{ section: 'Test Section', message: 'Test message' }];
const { container } = render(<ErrorMessages errors={errors} />);
expect(screen.getByText('Test Section:')).toBeInTheDocument();
expect(container).toHaveTextContent('Test message');
});
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/app/[username]/components/ErrorMessages.test.tsx
Line: 17-23

Comment:
`screen.getByText('Test message')` はエラーをスローします。`{err.message}` はコンポーネント内で `<strong>` の隣にある裸のテキストノードとして描画されるため、DOM 要素の `textContent` が完全一致する要素が存在しません(外側の `div``textContent``"Test Section: Test message"` になります)。`getByText` はデフォルトで `exact: true` で動作するため、一致する要素が見つからず `TestingLibraryElementError` がスローされてテストが失敗します。`container.toHaveTextContent` を使うと、コンテナの textContent に文字列が含まれているかを検証できます。

```suggestion
  it('renders a single error message correctly', () => {
    const errors = [{ section: 'Test Section', message: 'Test message' }];
    const { container } = render(<ErrorMessages errors={errors} />);

    expect(screen.getByText('Test Section:')).toBeInTheDocument();
    expect(container).toHaveTextContent('Test message');
  });
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +25 to +36
it('renders multiple error messages correctly', () => {
const errors = [
{ section: 'Section 1', message: 'Message 1' },
{ section: 'Section 2', message: 'Message 2' },
];
render(<ErrorMessages errors={errors} />);

expect(screen.getByText('Section 1:')).toBeInTheDocument();
expect(screen.getByText('Message 1')).toBeInTheDocument();
expect(screen.getByText('Section 2:')).toBeInTheDocument();
expect(screen.getByText('Message 2')).toBeInTheDocument();
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 複数エラーのテストでも同じ問題が発生します。'Message 1' / 'Message 2' はいずれも単独の DOM 要素に紐付かない裸のテキストノードであるため、getByText でそれぞれを検索すると TestingLibraryElementError がスローされてテストが失敗します。container.toHaveTextContent に変更してください。

Suggested change
it('renders multiple error messages correctly', () => {
const errors = [
{ section: 'Section 1', message: 'Message 1' },
{ section: 'Section 2', message: 'Message 2' },
];
render(<ErrorMessages errors={errors} />);
expect(screen.getByText('Section 1:')).toBeInTheDocument();
expect(screen.getByText('Message 1')).toBeInTheDocument();
expect(screen.getByText('Section 2:')).toBeInTheDocument();
expect(screen.getByText('Message 2')).toBeInTheDocument();
});
it('renders multiple error messages correctly', () => {
const errors = [
{ section: 'Section 1', message: 'Message 1' },
{ section: 'Section 2', message: 'Message 2' },
];
const { container } = render(<ErrorMessages errors={errors} />);
expect(screen.getByText('Section 1:')).toBeInTheDocument();
expect(container).toHaveTextContent('Message 1');
expect(screen.getByText('Section 2:')).toBeInTheDocument();
expect(container).toHaveTextContent('Message 2');
});
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/app/[username]/components/ErrorMessages.test.tsx
Line: 25-36

Comment:
複数エラーのテストでも同じ問題が発生します。`'Message 1'` / `'Message 2'` はいずれも単独の DOM 要素に紐付かない裸のテキストノードであるため、`getByText` でそれぞれを検索すると `TestingLibraryElementError` がスローされてテストが失敗します。`container.toHaveTextContent` に変更してください。

```suggestion
  it('renders multiple error messages correctly', () => {
    const errors = [
      { section: 'Section 1', message: 'Message 1' },
      { section: 'Section 2', message: 'Message 2' },
    ];
    const { container } = render(<ErrorMessages errors={errors} />);

    expect(screen.getByText('Section 1:')).toBeInTheDocument();
    expect(container).toHaveTextContent('Message 1');
    expect(screen.getByText('Section 2:')).toBeInTheDocument();
    expect(container).toHaveTextContent('Message 2');
  });
```

How can I resolve this? If you propose a fix, please make it concise.

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.

1 participant