Skip to content

Pass distinct props (testid) to each MockComponent instance#2728

Open
thedavidmeister wants to merge 1 commit into
mainfrom
2026-06-13-issue-1842
Open

Pass distinct props (testid) to each MockComponent instance#2728
thedavidmeister wants to merge 1 commit into
mainfrom
2026-06-13-issue-1842

Conversation

@thedavidmeister

Copy link
Copy Markdown
Contributor

Fixes #1842

Motivation

The ui-components mock at packages/ui-components/src/lib/__mocks__/MockComponent.svelte still carried the reactive props store ($: $props = $$props) that #1840 identified as the cause of the RangeError: Invalid array length crash/hang when a test mounts more than one instance. PR #1841 only fixed the webapp copy of the mock; this one was left untouched. There was also no way to give each instance distinct props (e.g. a testid) so multiple instances could be told apart.

Solution

Rework the ui-components mock so it:

  • Mirrors the received props into the shared props store from afterUpdate instead of a reactive $: block, so it never re-enters the component update cycle that exhausted the dirty array across multiple instances (the MockComponent is throwing invalid array length errors #1840 crash/hang).
  • Exports a testid prop (default "mock-component") that drives data-testid, so a test mounting more than one instance can give each a distinct id and query them individually. Remaining props are still spread onto the element and into the store, so existing attribute- and store-based assertions keep working (License, CodeMirror*, TanstackLightweightChartLine).

Tests

Added MockComponent.test.ts (plus a MockComponent.test.svelte harness) with discriminating assertions:

  • default data-testid is mock-component;
  • a testid prop overrides data-testid and removes the default id;
  • remaining props are spread as element attributes and testid is not duplicated as a testid attribute;
  • the shared store mirrors received props (including non-serializable values like functions) and excludes testid;
  • mounting more than one instance with distinct testids renders both, queryable individually, with per-instance props and slot content.

Verification

  • Full ui-components vitest suite: 640 passed. The only red, ShareChoicesButton > shows and hides copied message when clicked, is a pre-existing flaky CSS-animation timing test unrelated to this change — it passes on an isolated rerun.
  • Discrimination check: running the new MockComponent.test.ts against the original (unfixed) mock hangs on the multi-instance test — the exact MockComponent is throwing invalid array length errors #1840 symptom — confirming the test would catch a regression.

🤖 Generated with Claude Code

The ui-components mock at packages/ui-components/src/lib/__mocks__/
MockComponent.svelte still carried the reactive props store
(`$: $props = $$props`) that issue #1840 identified as the cause of the
"RangeError: Invalid array length" crash when a test mounts more than one
instance. PR #1841 only fixed the webapp copy.

Rework the ui-components mock so:

- It mirrors received props into the shared store from `afterUpdate` instead
  of a reactive `$:` block, so it never re-enters the component update cycle
  that exhausted the dirty array across multiple instances.
- It exports a `testid` prop (default "mock-component") that drives
  `data-testid`, so a test mounting more than one instance can give each a
  distinct id and query them individually. Remaining props are still spread
  onto the element and into the store, preserving existing attribute- and
  store-based assertions (License, CodeMirror*, TanstackLightweightChartLine).

Add MockComponent.test.ts (+ a .test.svelte harness) covering the default
testid, an overridden testid, prop spreading, store mirroring, and the
multi-instance #1840 scenario.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@thedavidmeister thedavidmeister self-assigned this Jun 13, 2026
@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

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

More reviews will be available in 51 minutes and 41 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 86b95735-2501-4265-bc6d-61ecd8d11ba0

📥 Commits

Reviewing files that changed from the base of the PR and between 31e7a49 and b294ced.

📒 Files selected for processing (3)
  • packages/ui-components/src/__tests__/MockComponent.test.svelte
  • packages/ui-components/src/__tests__/MockComponent.test.ts
  • packages/ui-components/src/lib/__mocks__/MockComponent.svelte
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 2026-06-13-issue-1842

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Find a way to pass different props to each instance of MockComponent in test files

1 participant