test: use mockTheme instead of hardcoded hex values in test assertions#26657
test: use mockTheme instead of hardcoded hex values in test assertions#26657georgewrmarshall merged 8 commits intomainfrom
Conversation
Replace hardcoded hex color values with design token references in test files to make tests resilient to future design token upgrades. This unblocks PR #26639 (design token upgrade to v8.2.1) by ensuring tests assert the correct design token is used rather than specific hex values that change between token versions. Updated test files: - app/components/Snaps/SnapUIRenderer/components/input.test.ts - app/components/UI/Bridge/components/TransactionDetails/BridgeStepDescription.test.tsx - app/components/UI/Card/components/Onboarding/VerifyIdentity.test.tsx - app/components/UI/Earn/Views/EarnLendingWithdrawalConfirmationView/EarnLendingWithdrawalConfirmationView.test.tsx - app/components/UI/Rewards/hooks/useRewardsToast.test.tsx - app/components/Views/confirmations/components/UI/info-row-divider/info-row-divider.test.tsx Approach: - Import lightTheme from @metamask/design-tokens - Replace hex values with lightTheme.colors.* references - Update theme mocks to use jest.requireActual('@metamask/design-tokens') - Update snapshots to reflect new token values
|
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. |
app/components/UI/Card/components/Onboarding/VerifyIdentity.test.tsx
Outdated
Show resolved
Hide resolved
app/components/Views/confirmations/components/UI/info-row-divider/info-row-divider.test.tsx
Outdated
Show resolved
Hide resolved
- Use mockTheme instead of lightTheme for consistency with codebase - Use correct brandColor tokens (grey900/grey000) for camera overlay in VerifyIdentity test - Remove template interpolation from inline snapshot in info-row-divider test (Jest cannot update snapshots with template literals) - Update snapshots to reflect design token values
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Autofix Details
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Mock doesn't re-export
mockTheme, causing undefined access- Updated the local theme mock to spread actual exports while overriding
useAppThemeFromContext, preservingmockThemefor imports used in assertions.
- Updated the local theme mock to spread actual exports while overriding
Or push these changes by commenting:
@cursor push 3032f9806f
Preview (3032f9806f)
diff --git a/app/components/UI/Rewards/hooks/useRewardsToast.test.tsx b/app/components/UI/Rewards/hooks/useRewardsToast.test.tsx
--- a/app/components/UI/Rewards/hooks/useRewardsToast.test.tsx
+++ b/app/components/UI/Rewards/hooks/useRewardsToast.test.tsx
@@ -36,6 +36,7 @@
jest.mock('../../../../util/theme', () => {
const actualTheme = jest.requireActual('../../../../util/theme');
return {
+ ...actualTheme,
useAppThemeFromContext: () => actualTheme.mockTheme,
};
});Fix `useRewardsToast` test mock to correctly re-export `mockTheme`, resolving `TypeError`s due to undefined access. --- <!-- CURSOR_SUMMARY --> > [!NOTE] > **Low Risk** > Low risk: test-only change that fixes a Jest mock to include the real theme exports, preventing `mockTheme` from being `undefined`. No production logic is modified. > > **Overview** > Fixes `useRewardsToast.test.tsx` by updating the `../../../../util/theme` Jest mock to spread `jest.requireActual` exports, ensuring `mockTheme` and other module exports remain available while still overriding `useAppThemeFromContext`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 3032f98. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
| describe('SnapUIInput', () => { | ||
| const clearBorderColor = '#b7bbc866'; | ||
| const focusedBorderColor = '#b7bbc8'; | ||
| const clearBorderColor = mockTheme.colors.border.muted; |
There was a problem hiding this comment.
Using mockTheme.colors.border references instead of hex values. Updated to use latest color conventions for focus
| expect(textElement.props.style).toHaveProperty('color', '#686e7d'); | ||
| expect(textElement.props.style).toHaveProperty( | ||
| 'color', | ||
| mockTheme.colors.text.alternative, |
There was a problem hiding this comment.
These test assertions verify the component uses correct design tokens for text colors. This pattern allows tests to validate token usage while automatically adapting when token values change in future design system updates.
| const actualTheme = jest.requireActual('../../../../util/theme'); | ||
| return { | ||
| ...actualTheme, | ||
| useAppThemeFromContext: () => actualTheme.mockTheme, |
There was a problem hiding this comment.
The theme mock now uses jest.requireActual to import the real mockTheme object. This ensures tests use actual design token values rather than custom mock values that could drift from production.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Autofix Details
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Inline snapshot replacement drops non-color style assertions
- Restored individual assertions for height and margins in the test while keeping the backgroundColor token check.
Or push these changes by commenting:
@cursor push fa7d2eabc4
Preview (fa7d2eabc4)
diff --git a/app/components/Views/confirmations/components/UI/info-row-divider/info-row-divider.test.tsx b/app/components/Views/confirmations/components/UI/info-row-divider/info-row-divider.test.tsx
--- a/app/components/Views/confirmations/components/UI/info-row-divider/info-row-divider.test.tsx
+++ b/app/components/Views/confirmations/components/UI/info-row-divider/info-row-divider.test.tsx
@@ -15,5 +15,10 @@
expect(result?.props?.style?.backgroundColor).toBe(
mockTheme.colors.border.muted,
);
+ // Verify static layout properties remain unchanged
+ expect(result?.props?.style?.height).toBe(1);
+ expect(result?.props?.style?.marginLeft).toBe(-8);
+ expect(result?.props?.style?.marginRight).toBe(-8);
+ expect(result?.props?.style?.marginVertical).toBe(8);
});
});
app/components/Views/confirmations/components/UI/info-row-divider/info-row-divider.test.tsx
Outdated
Show resolved
Hide resolved
| cameraOverlay: '#121314', | ||
| onCameraOverlay: '#ffffff', | ||
| cameraOverlay: mockTheme.brandColors.grey900, | ||
| onCameraOverlay: mockTheme.brandColors.grey000, |
There was a problem hiding this comment.
Camera overlay colors use mockTheme.brandColors instead of theme.colors because they are static values that should not change with theme. The camera overlay is always dark with white text regardless of light or dark theme mode.
| marginLeft: -8, | ||
| marginRight: -8, | ||
| marginVertical: 8, | ||
| }); |
There was a problem hiding this comment.
Changed from inline snapshot to explicit style assertion for better maintainability. This approach verifies all layout properties while using design token reference for backgroundColor. Jest cannot update snapshots with template interpolation, so explicit assertions allow automatic updates when token values change.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Conditional guard silently skips main style assertion
- Replaced the conditional guard with an explicit non-array assertion and an unconditional style assertion so the test fails loudly instead of skipping the main check.
Or push these changes by commenting:
@cursor push 84f6c90c14
Preview (84f6c90c14)
diff --git a/app/components/Views/confirmations/components/UI/info-row-divider/info-row-divider.test.tsx b/app/components/Views/confirmations/components/UI/info-row-divider/info-row-divider.test.tsx
--- a/app/components/Views/confirmations/components/UI/info-row-divider/info-row-divider.test.tsx
+++ b/app/components/Views/confirmations/components/UI/info-row-divider/info-row-divider.test.tsx
@@ -12,14 +12,13 @@
const result = toJSON();
expect(result).toBeTruthy();
- if (result && !Array.isArray(result)) {
- expect(result.props.style).toEqual({
- backgroundColor: mockTheme.colors.border.muted,
- height: 1,
- marginLeft: -8,
- marginRight: -8,
- marginVertical: 8,
- });
- }
+ expect(Array.isArray(result)).toBe(false);
+ expect((result as any).props.style).toEqual({
+ backgroundColor: mockTheme.colors.border.muted,
+ height: 1,
+ marginLeft: -8,
+ marginRight: -8,
+ marginVertical: 8,
+ });
});
});
app/components/Views/confirmations/components/UI/info-row-divider/info-row-divider.test.tsx
Show resolved
Hide resolved
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection: Performance Test Selection: |

Description
This PR updates test files to use design token references instead of hardcoded hex values, unblocking the design tokens upgrade to v8.2.1 (#26639).
What this PR does:
mockTheme.colors.*references in test assertionsbrandColor.*for static, non-theme-dependent colors (camera overlay)Why this is an improvement:
Changelog
CHANGELOG entry: null
Related issues
Dependency of: #26639
Related: #26651
Manual testing steps
Screenshots/Recordings
N/A - Test-only changes
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Low Risk
Test-only changes that update assertions to reference theme tokens, reducing brittleness during design-token updates. Low risk aside from potential snapshot/assertion adjustments if token mappings differ.
Overview
Updates several UI/unit tests to assert against theme design tokens (via
mockTheme.colors.*) instead of hardcoded hex values, including Snap UI input borders, Bridge step text colors, Earn navbar background, and Rewards toast icon colors.Adjusts tests that relied on inline snapshots/mocked theme shapes by switching to token-backed assertions (and using
brandColorsfor static camera overlay colors in Veriff branding) to keep tests resilient to design-token value changes.Written by Cursor Bugbot for commit 04dc67e. This will update automatically on new commits. Configure here.