Skip to content

chore: update unit testing cursor rule for theme mocks#27825

Merged
georgewrmarshall merged 5 commits intomainfrom
cursor-rule-theme-mocks
Mar 24, 2026
Merged

chore: update unit testing cursor rule for theme mocks#27825
georgewrmarshall merged 5 commits intomainfrom
cursor-rule-theme-mocks

Conversation

@georgewrmarshall
Copy link
Copy Markdown
Contributor

@georgewrmarshall georgewrmarshall commented Mar 23, 2026

Description

Updates .cursor/rules/unit-testing-guidelines.mdc with clearer guidance for theme-related mocks in unit tests:

  • Prefer mockTheme (real design tokens) instead of hardcoded hex values.
  • Mock useTailwind() with the correct return shape (supports tw.style(...), and only add tw.color(...) when the component under test uses it).

This is intended to reduce churn and align new tests with the @metamask/design-tokens/color-no-hex ESLint rule.

Related / prior color-no-hex PRs:

Changelog

CHANGELOG entry: null

Related issues

Fixes:

Manual testing steps

Feature: Cursor unit testing guidelines

  Scenario: guidance for theme-related mocks is clear
    Given a developer is writing or updating a unit test
    When they follow the updated theme mocking guidance
    Then they can avoid hardcoded hex colors and mock useTailwind without type/shape mismatches

Screenshots/Recordings

Before

N/A

After

N/A

Pre-merge author checklist

  • I've followed MetaMask Contributor Docs and MetaMask Mobile Coding Standards.
  • I've completed the PR template to the best of my ability
  • I've included tests if applicable (N/A)
  • I've documented my code using JSDoc format if applicable (N/A)
  • I've applied the right labels on the PR (see labeling guidelines). Not required for external contributors.

Note

Low Risk
Low risk: documentation-only change that updates testing guidance without affecting runtime behavior.

Overview
Updates .cursor/rules/unit-testing-guidelines.mdc to add Theme Mocking Rules that steer tests toward using the shared mockTheme and away from hardcoded hex design tokens (to align with @metamask/design-tokens/color-no-hex).

Adds concrete mock examples for useTheme, useStyles, and useTailwind() (including the correct return shape), plus an explicit anti-pattern example of local hex color mock objects.

Written by Cursor Bugbot for commit 6227068. This will update automatically on new commits. Configure here.

@github-actions
Copy link
Copy Markdown
Contributor

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.

@metamaskbot metamaskbot added team-design-system All issues relating to design system in Mobile INVALID-PR-TEMPLATE PR's body doesn't match template labels Mar 23, 2026
@github-actions github-actions bot added size-S and removed size-M labels Mar 23, 2026
@georgewrmarshall georgewrmarshall self-assigned this Mar 23, 2026
@georgewrmarshall georgewrmarshall marked this pull request as ready for review March 23, 2026 20:05
@georgewrmarshall georgewrmarshall requested a review from a team March 23, 2026 20:05
### Theme Mocking Rules

- **Prefer shared `mockTheme` from `app/util/theme`** instead of hard-coded color literals in tests.
- **Never hardcode design token hex values** in assertions or theme mocks (enforced by `@metamask/design-tokens/color-no-hex`).
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This codifies the approach used across the color-no-hex cleanup PRs (e.g. #26958, #26963, #27030): prefer util/theme mockTheme and avoid hardcoded hex so design token updates don’t create test churn.

```

```ts
// ✅ CORRECT: mock useTailwind with the right shape
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This useTailwind mock is intentionally minimal because most components only call tw.style; adding extra helpers tends to diverge across tests and makes future token changes harder to standardize.

```

```ts
// ✅ ALSO CORRECT: match real useTailwind() return type (callable function + helpers)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some tests treat the useTailwind return value as callable plus a .style helper (see existing patterns like ManualBackupStep1), so this optional shape helps avoid mismatch bugs; we intentionally don’t mention tw.color since it’s rarely used.

@github-actions
Copy link
Copy Markdown
Contributor

E2E Fixture Validation — Schema is up to date
17 value mismatches detected (expected — fixture represents an existing user).
View details

@github-actions github-actions bot added the risk-low Low testing needed · Low bug introduction risk label Mar 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: None (no tests recommended)
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: low
  • AI Confidence: 99%
click to see 🤖 AI reasoning details

E2E Test Selection:
The only changed file is .cursor/rules/unit-testing-guidelines.mdc, which is a Cursor IDE rules/documentation file. The diff shows it adds developer guidelines about theme mocking practices for unit tests (using mockTheme instead of hardcoded hex colors). This is purely documentation — it has zero impact on application code, E2E test infrastructure, controllers, components, or any user-facing functionality. No E2E tests need to run for this change.

Performance Test Selection:
The change is purely documentation (Cursor IDE rules file for unit testing guidelines). There is no application code, UI component, or performance-sensitive code modified. No performance tests are warranted.

View GitHub Actions results

@sonarqubecloud
Copy link
Copy Markdown

@georgewrmarshall georgewrmarshall added this pull request to the merge queue Mar 24, 2026
Merged via the queue into main with commit 025e1ef Mar 24, 2026
60 of 62 checks passed
@georgewrmarshall georgewrmarshall deleted the cursor-rule-theme-mocks branch March 24, 2026 21:09
@github-actions github-actions bot locked and limited conversation to collaborators Mar 24, 2026
@metamaskbot metamaskbot added the release-7.72.0 Issue or pull request that will be included in release 7.72.0 label Mar 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

INVALID-PR-TEMPLATE PR's body doesn't match template release-7.72.0 Issue or pull request that will be included in release 7.72.0 risk-low Low testing needed · Low bug introduction risk size-S team-design-system All issues relating to design system in Mobile

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants