fix: replace static hex colors with design tokens in test files#26396
Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
...mponents/Views/confirmations/components/send/amount/amount-keyboard/amount-keyboard.test.tsx
Outdated
Show resolved
Hide resolved
|
Resolved merge conflicts with main — most of the hex-to-token replacements were already done upstream using @georgewrmarshall could you take a look when you get a chance? You opened the original issue (#14299) so you'd be the best person to review. cc @wachunei |
app/components/Views/ChoosePassword/FoxRiveLoaderAnimation/index.test.tsx
Outdated
Show resolved
Hide resolved
...gs/Sections/MetaMetricsAndDataCollectionSection/MetaMetricsAndDataCollectionSection.test.tsx
Outdated
Show resolved
Hide resolved
...gs/Sections/MetaMetricsAndDataCollectionSection/MetaMetricsAndDataCollectionSection.test.tsx
Outdated
Show resolved
Hide resolved
...ettings/Sections/MetaMetricsAndDataCollectionSection/MetaMetricsAndDataCollectionSection.tsx
Outdated
Show resolved
Hide resolved
app/components/Views/Settings/SecuritySettings/Sections/BlockaidSettings.tsx
Outdated
Show resolved
Hide resolved
I started reviewing but I'm noticing some unrelated changes, are those intended? |
|
Thanks for catching that @wachunei! The unrelated analytics/production changes (ExperienceEnhancerModal, BlockaidSettings, MetaMetricsAndDataCollectionSection, UserProfileAnalyticsMetaData types) were accidentally included from a shared branch base with PR #26792. I've reverted all of them — this PR now only touches 8 test files with hex color → design token replacements, zero production code changes. Also moved the Please take another look! |
There was a problem hiding this comment.
Thanks again for taking this on! Replacing hardcoded hex literals with design token references is exactly the right direction, and the mapping table in the PR description is a great touch for reviewers.
A few suggestions below to align with patterns that have landed in recent PRs (#27149, #27031, #27030, #27008). The core idea: for tests that are exercising a component or hook that consumes the theme, prefer mockTheme from util/theme over importing brandColor directly from @metamask/design-tokens. mockTheme is the project's canonical test theme — it wraps lightTheme internally — so it keeps test expectations decoupled from raw token values while still tracking the design system. There is one important exception explained in the inline comment on ThemeProvider.test.tsx.
app/components/UI/ContextualNetworkPicker/ContextualNetworkPicker.test.tsx
Outdated
Show resolved
Hide resolved
app/components/Views/ChoosePassword/FoxRiveLoaderAnimation/index.test.tsx
Outdated
Show resolved
Hide resolved
|
@georgewrmarshall Thanks for the detailed review! I've addressed all 5 suggestions:
Left |
app/components/UI/ContextualNetworkPicker/ContextualNetworkPicker.test.tsx
Show resolved
Hide resolved
Replace hardcoded hex color values with design token references (brandColor, mockTheme) in test files for consistency and maintainability. - Use brandColor from @metamask/design-tokens for color assertions - Use mockTheme from util/theme for theme-dependent test values - Fix jest.mock factory to properly re-export mockTheme alongside useTheme
ff6a952 to
060894b
Compare
|
Thanks for making the latest updates! I have made a few follow-up updates to fix the failing tests, including the mocked module export issue for mockTheme, and rebased the branch onto the latest main. I also ran linting, type checks, and the updated test files to verify everything is passing on this branch. We will get this PR reviewed by the team soon. Thanks again for your contribution! |
Thank you @georgewrmarshall for helping me out, appreciate it. I hope the team can review it and final changes (if required) can be done and we can merge this. |
Matt561
left a comment
There was a problem hiding this comment.
Approving for the 2 Earn-owned files 👍
|
Hi @georgewrmarshall , whom do I tag for a review from MetaMask/design-system-engineers. PTAL when you get the time. Thank you |

Description
Resolves #14299
Replaces hardcoded hex color literals with
brandColorandlightThemetokens from@metamask/design-tokensacross 37 test files (~120 replacements).Color mappings applied
#ffffff/#FFFFFF/#fff/#FFFbrandColor.white#000000/#000brandColor.black#4459ffbrandColor.blue500#ca3542lightTheme.colors.error.default#457a39lightTheme.colors.success.default#b7bbc8lightTheme.colors.border.default#686e7dbrandColor.grey500#9ca1afbrandColor.grey300#121314brandColor.grey900#2c3dc5brandColor.blue600#1c7e33brandColor.green500#279f41brandColor.green400What was intentionally skipped
jest.mock()factories — babel-jest hoists mock factories before imports resolve, so referencingbrandColor/lightThemethere causesReferenceError: The module factory of jest.mock() is not allowed to reference any out-of-scope variablestoHaveBeenCalledWithmatching exact hex strings sent by non-test code)#b7bbc866)#FF0000,#666666,#002244,#FB4F14, etc.)Scope
This PR only touches test files — no production code changes.
Manual testing steps
N/A — mechanical replacement of string literals with equivalent design token references.
Screenshots/Recordings
N/A
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Low Risk
Test-only updates that swap hardcoded color literals for
@metamask/design-tokens/mockThemevalues; low risk aside from potential Jest mock/expectation mismatches if tokens change.Overview
Updates multiple unit tests to stop asserting/constructing UI colors via hardcoded hex strings and instead reference
@metamask/design-tokens(brandColor) and the sharedmockThemefromutil/theme.Also refactors several test
useThememocks to returnmockTheme(viajest.requireActual) so style/toast expectations align with the app’s theme tokens.Written by Cursor Bugbot for commit 060894b. This will update automatically on new commits. Configure here.