This repository was archived by the owner on Aug 5, 2026. It is now read-only.
Repository navigation
[BpkStarRating] Replace snapshot tests with explicit assertions - #4670
Merged
Faye (Faye-Xiao) merged 1 commit intoJun 5, 2026
Merged
Faye (Faye-Xiao) merged 1 commit into
Faye (Faye-Xiao) merged 1 commit into
Conversation
The 30 toMatchSnapshot() calls across the 5 test files in bpk-component-star-rating verified rendered HTML by full-DOM diff, which obscures intent and tends to pass silently after an accidental --updateSnapshot. Replace them with assertions that name the behaviour each test is checking: - BpkStar: assert presence/absence of star modifier classes per type and size, plus className passthrough. - BpkInteractiveStar: assert the role=button, aria-label, aria-pressed, and the inner star fill state per type/selected combo. - BpkStarRating: assert the role=img, aria-label, and the count of full/half/empty stars per rating, including maxRating and rounding behaviour. - BpkInteractiveStarRating: assert the rendered button count, fill count per rating/maxRating/hoverRating, and that onRatingHover / onRatingSelect get called with the correct star number. - withInteractiveStarRatingState: assert the initial state, that click selects (aria-pressed=true) and that hover only previews (aria-pressed stays false). Also delete the now-orphaned __snapshots__/*.snap files. No production code changes; jest now reports 0 snapshots for this package. Co-Authored-By: Claude Opus 4.7 <[email protected]>
3 tasks done
Faye (Faye-Xiao)
approved these changes
Jun 5, 2026
Vincent Liu (xiaogliu)
added a commit
that referenced
this pull request
Jun 8, 2026
* [BpkStarRating] Migrate JS to TypeScript Convert the bpk-component-star-rating package from JavaScript/Flow to TypeScript. Replace prop-types and Flow types with typed Props exports and rename all source/test/snapshot files (.js -> .ts/.tsx). No business-logic, JSX, or rendering changes - existing snapshots remain valid. - Rename index.js -> index.ts and re-export per-component *Props types - Rename BpkStar/BpkStarRating/BpkInteractiveStar/BpkInteractiveStarRating to .tsx with typed Props exports; keep className?: string | null and destructuring defaults in place of defaultProps - Convert STAR_TYPES to as const and derive a StarType union - Migrate withInteractiveStarRatingState to .tsx with a generic class component and a public static displayName field - Rename themeAttributes/accessibility/themeAttributes-test files - Rename snapshot files to *-test.tsx.snap so Jest finds them under the new test filenames - Drop the now-unused @ts-expect-error suppressions on the index/component imports in the stories file Co-Authored-By: Claude Opus 4.7 <[email protected]> * [BpkStarRating] Drop now-unused @ts-expect-error on consumers After typing the star-rating package, the @ts-expect-error suppressions on its imports in BpkRating.stories and BpkCardV2.stories became unused directives, breaking `tsc --noEmit`. Remove them. Co-Authored-By: Claude Opus 4.7 <[email protected]> * [BpkStarRating] Address review feedback - BpkStar: fix half-star className being a comma-separated string at runtime. Pre-existing bug from JS code that the TS migration's `as unknown as string` cast was hiding. Use `.join(' ')` so the half star gets a valid space-separated class list. Updates 4 half-star snapshots accordingly. - withInteractiveStarRatingState: drop the `event.persist()` call and its `as SyntheticEvent` cast — `persist()` has been a no-op since React 17. - withInteractiveStarRatingState: destructure HOC-owned `onRatingSelect` out of `this.props` before spreading, so only `P` props are forwarded to the wrapped component. Co-Authored-By: Claude Opus 4.7 <[email protected]> * [BpkStarRating] Replace snapshot tests with explicit assertions (#4670) The 30 toMatchSnapshot() calls across the 5 test files in bpk-component-star-rating verified rendered HTML by full-DOM diff, which obscures intent and tends to pass silently after an accidental --updateSnapshot. Replace them with assertions that name the behaviour each test is checking: - BpkStar: assert presence/absence of star modifier classes per type and size, plus className passthrough. - BpkInteractiveStar: assert the role=button, aria-label, aria-pressed, and the inner star fill state per type/selected combo. - BpkStarRating: assert the role=img, aria-label, and the count of full/half/empty stars per rating, including maxRating and rounding behaviour. - BpkInteractiveStarRating: assert the rendered button count, fill count per rating/maxRating/hoverRating, and that onRatingHover / onRatingSelect get called with the correct star number. - withInteractiveStarRatingState: assert the initial state, that click selects (aria-pressed=true) and that hover only previews (aria-pressed stays false). Also delete the now-orphaned __snapshots__/*.snap files. No production code changes; jest now reports 0 snapshots for this package. Co-authored-by: Vincent Liu <[email protected]> Co-authored-by: Claude Opus 4.7 <[email protected]> --------- Co-authored-by: Vincent Liu <[email protected]> Co-authored-by: Claude Opus 4.7 <[email protected]> Co-authored-by: Faye <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stacked on top of #4523 — replaces all 30 `toMatchSnapshot()` calls across the 5 test files in `bpk-component-star-rating` with explicit assertions that name the behaviour each test is checking, addressing #4523 (comment).
The five rewritten files now assert on:
The `snapshots/*.snap` files are deleted. `getTypeByRating` unit tests are kept as-is — they were already explicit.
No production code changes.
Test plan
🤖 Generated with Claude Code