Commit 29f05cf
authored
test: add lint rule to prevent new snapshot tests (#28582)
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->
## **Description**
>
> Prevents new file-based Jest snapshots by enabling
jest/no-restricted-matchers for *.test/*.spec files and explicitly
disallowing toMatchSnapshot() (while still permitting
toMatchInlineSnapshot()).
>
> Adds a targeted override that turns this restriction off for tests
under **/snaps/** and **/Snaps/**, and includes eslint-plugin-jest as a
new devDependency (lockfile updated accordingly).
## **Changelog**
<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
2. Label with `no-changelog`
If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`
(This helps the Release Engineer do their job more quickly and
accurately)
-->
CHANGELOG entry:
## **Related issues**
Fixes:
## **Manual testing steps**
```gherkin
Feature: my feature name
Scenario: user [verb for user action]
Given [describe expected initial app state]
When user [verb for user action]
Then [describe expected outcome]
```
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
### **After**
<!-- [screenshots/recordings] -->
## **Pre-merge author checklist**
- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I've included tests if applicable
- [ ] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I've applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **Pre-merge reviewer checklist**
- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Adds a new ESLint enforcement that will fail builds for any
remaining/new `toMatchSnapshot()` usage in `*.test`/`*.spec` files,
which could cause unexpected CI failures until all tests comply. Code
changes are otherwise limited to test assertions and dev tooling.
>
> **Overview**
> **Prevents new file-based Jest snapshots** by enabling
`eslint-plugin-jest` and enforcing `jest/no-restricted-matchers` to
disallow `toMatchSnapshot()` across `*.test`/`*.spec` files, while
explicitly exempting tests under `**/snaps/**` and `**/Snaps/**`.
>
> Refactors a handful of existing tests (e.g., `BadgeWrapper`, `Main`,
`AssetElement`, `SettingsNotification`, `StyledButton`, `TabCountIcon`,
`Root`) to replace snapshot assertions with targeted
`@testing-library/react-native` queries, and removes the corresponding
snapshot files (including deleting the `TokenImage` snapshot test
entirely).
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
728a801. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent d5c2f24 commit 29f05cf
21 files changed
Lines changed: 84 additions & 2604 deletions
File tree
- app
- component-library/components/Badges/BadgeWrapper
- __snapshots__
- components
- UI
- AccountFromToInfoCard
- __snapshots__
- AssetElement
- __snapshots__
- SettingsNotification
- __snapshots__
- StyledButton
- __snapshots__
- Tabs/TabCountIcon
- __snapshots__
- TokenImage
- __snapshots__
- Views/Root
- __snapshots__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
385 | 385 | | |
386 | 386 | | |
387 | 387 | | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
388 | 415 | | |
389 | 416 | | |
390 | 417 | | |
| |||
Lines changed: 8 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
17 | 21 | | |
18 | 22 | | |
Lines changed: 0 additions & 122 deletions
This file was deleted.
0 commit comments