Pass distinct props (testid) to each MockComponent instance#2728
Pass distinct props (testid) to each MockComponent instance#2728thedavidmeister wants to merge 1 commit into
Conversation
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>
|
Warning Review limit reached
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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Fixes #1842
Motivation
The
ui-componentsmock atpackages/ui-components/src/lib/__mocks__/MockComponent.sveltestill carried the reactive props store ($: $props = $$props) that #1840 identified as the cause of theRangeError: Invalid array lengthcrash/hang when a test mounts more than one instance. PR #1841 only fixed thewebappcopy of the mock; this one was left untouched. There was also no way to give each instance distinct props (e.g. atestid) so multiple instances could be told apart.Solution
Rework the
ui-componentsmock so it:propsstore fromafterUpdateinstead 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).testidprop (default"mock-component") that drivesdata-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 aMockComponent.test.svelteharness) with discriminating assertions:data-testidismock-component;testidprop overridesdata-testidand removes the default id;testidis not duplicated as atestidattribute;testid;Verification
ui-componentsvitest 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.MockComponent.test.tsagainst 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