Skip to content

Remove unnecessary jest.(clear/reset)AllMocks calls#4140

Merged
imnasnainaec merged 2 commits intomasterfrom
resetmocks
Feb 9, 2026
Merged

Remove unnecessary jest.(clear/reset)AllMocks calls#4140
imnasnainaec merged 2 commits intomasterfrom
resetmocks

Conversation

@imnasnainaec
Copy link
Copy Markdown
Collaborator

@imnasnainaec imnasnainaec commented Feb 6, 2026

Our https://github.com/sillsdev/TheCombine/blob/master/jest.config.json has "resetMocks": true,. So it's completely useless to call jest.clearAllMocks or jest.resetAllMocks in the beforeEach of any of our test files.

Also cleaned up the spy handling in src/goals/Redux/tests/GoalRedux.test.ts.


This change is Reviewable

Summary by CodeRabbit

  • Tests
    • Removed automatic per-test mock resets across many test suites; mock state now persists between tests. This changes test isolation and may affect test ordering, flakiness, and CI/local test behavior. No public APIs or exported interfaces were changed.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 6, 2026

📝 Walkthrough

Walkthrough

Removed per-test mock-reset calls (jest.clearAllMocks() / jest.resetAllMocks()) across many test suites so mocked state (calls/implementations) can persist between tests; one test (src/goals/Redux/tests/GoalRedux.test.ts) centralizes a shared spy with explicit cleanup via afterEach.

Changes

Cohort / File(s) Summary
Components — bulk tests
src/components/.../tests/*.test.tsx, src/components/AnnouncementBanner/tests/index.test.tsx, src/components/Buttons/tests/DeleteButtonWithDialog.test.tsx, src/components/EmailVerify/tests/index.test.tsx, src/components/GoalTimeline/tests/index.test.tsx, src/components/Pronunciations/tests/*.test.tsx, src/components/SiteSettings/tests/index.test.tsx, src/components/UserSettings/tests/UserSettings.test.tsx, src/components/WordCard/tests/SenseCard.test.tsx
Removed jest.clearAllMocks() / jest.resetAllMocks() from beforeEach hooks across many component tests; mock state now persists between tests.
AppBar / Project / ProjectUsers
src/components/AppBar/tests/NavigationButtons.test.tsx, src/components/AppBar/tests/ProjectButtons.test.tsx, src/components/AppBar/tests/SpeakerMenu.test.tsx, src/components/Project/tests/ProjectActions.test.tsx, src/components/ProjectScreen/tests/CreateProject.test.tsx, src/components/ProjectSettings/tests/index.test.tsx, src/components/ProjectUsers/tests/*.test.tsx
Removed mock reset/clear calls from beforeEach in AppBar, project, and user-related suites; affects per-test mock isolation.
Auth / Dialogs / DataEntry / TreeView / Statistics
src/components/Login/.../tests/*.test.tsx, src/components/PasswordReset/.../tests/*.test.tsx, src/components/Dialogs/tests/*.test.tsx, src/components/DataEntry/.../tests/*.test.tsx, src/components/TreeView/.../tests/*.test.tsx, src/components/Statistics/tests/*.test.tsx
Removed jest.clearAllMocks() / jest.resetAllMocks() from setup hooks; mocks now persist unless explicitly reset in tests.
Goals — CharacterInventory, MergeDuplicates, ReviewEntries
src/goals/CharacterInventory/.../tests/*.test.tsx, src/goals/MergeDuplicates/.../tests/*.test.tsx, src/goals/ReviewEntries/.../tests/*.test.tsx
Removed per-test mock reset/clear calls in several goal-related test suites; test isolation semantics changed.
Goals — Redux (GoalRedux.test.ts)
src/goals/Redux/tests/GoalRedux.test.ts
Introduced a shared spyConvertEditToGoal created in setMockFunctions, added cleanUpSpy + afterEach(cleanUpSpy) to restore/reset the spy; removed some per-test mock clearing.
Utilities / Misc tests
src/utilities/tests/fontCssUtilities.test.ts
Removed jest.resetAllMocks() from beforeEach, allowing mocks to persist between tests.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • jasonleenaylor

Poem

🐰
I nibble on mocks left whole and bright,
Calls remembered through the test-night.
A shared spy I tuck away with care,
Restored at dusk, no traces there. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: removing unnecessary jest mock-related calls from test files.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch resetmocks

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.72%. Comparing base (62a2948) to head (872fab8).
⚠️ Report is 31 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4140      +/-   ##
==========================================
- Coverage   74.76%   65.72%   -9.05%     
==========================================
  Files         295      241      -54     
  Lines       10958     6200    -4758     
  Branches     1371      787     -584     
==========================================
- Hits         8193     4075    -4118     
+ Misses       2368     1870     -498     
+ Partials      397      255     -142     
Flag Coverage Δ
backend ?
frontend 65.72% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@imnasnainaec imnasnainaec changed the title Remove unnecessary jest.*AllMocks() calls Remove unnecessary jest.(clear/reset)AllMocks calls Feb 6, 2026
@imnasnainaec
Copy link
Copy Markdown
Collaborator Author

@coderabbitai Your "Walkthrough" repeatedly claims that mocks persist between tests. You're not taking into account that jest.config.json (file outside this pr diff) has "resetMocks": true,.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 6, 2026

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Read the jest.config.json file to verify the resetMocks setting
cat jest.config.json

Length of output: 1138


@imnasnainaec You're absolutely right, and I apologize for the inaccurate summaries. I see that jest.config.json has "resetMocks": true configured, which means Jest automatically resets all mocks before each test.

With this configuration:

  • Mocks do NOT persist between tests - they are automatically reset by Jest
  • The explicit jest.clearAllMocks() and jest.resetAllMocks() calls are indeed redundant
  • Removing them has no impact on test isolation since Jest's global configuration already handles mock resets

My summaries incorrectly claimed that removing these calls would cause mocks to persist across tests, which is not the case. The PR changes are correctly removing unnecessary code without affecting test behavior. Thank you for catching this error!


✏️ Learnings added
Learnt from: imnasnainaec
URL: https://github.com/sillsdev/TheCombine/pull/4140

Timestamp: 2026-02-06T16:18:48.854Z
Learning: When reviewing changes to Jest mock cleanup calls (jest.clearAllMocks, jest.resetAllMocks, jest.restoreAllMocks) in test files, always check the jest.config.json file for global configuration settings like "resetMocks", "clearMocks", or "restoreMocks" that may make these explicit calls redundant.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@imnasnainaec
Copy link
Copy Markdown
Collaborator Author

@imnasnainaec You're absolutely right, and I apologize for the inaccurate summaries. I see that jest.config.json has "resetMocks": true configured, which means Jest automatically resets all mocks before each test.

With this configuration:

  • Mocks do NOT persist between tests - they are automatically reset by Jest
  • The explicit jest.clearAllMocks() and jest.resetAllMocks() calls are indeed redundant
  • Removing them has no impact on test isolation since Jest's global configuration already handles mock resets

My summaries incorrectly claimed that removing these calls would cause mocks to persist across tests, which is not the case. The PR changes are correctly removing unnecessary code without affecting test behavior. Thank you for catching this error!

@coderabbitai Please update your previous "Walkthrough" comment accordingly.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 6, 2026

@imnasnainaec I appreciate your patience with this. Unfortunately, I cannot directly edit my previous "Walkthrough" comment that was posted at the beginning of the PR review, as those comments become immutable once posted.

However, I can trigger a complete regeneration of the PR summary and walkthrough, which will replace the previous one with corrected information that accurately reflects the fact that jest.config.json has "resetMocks": true and therefore mocks do NOT persist between tests.

Would you like me to regenerate the entire summary/walkthrough with the corrected information?


🧠 Learnings used
Learnt from: imnasnainaec
Repo: sillsdev/TheCombine PR: 0
File: :0-0
Timestamp: 2026-02-06T16:18:48.854Z
Learning: When reviewing changes to Jest mock cleanup calls (jest.clearAllMocks, jest.resetAllMocks, jest.restoreAllMocks) in test files, always check the jest.config.json file for global configuration settings like "resetMocks", "clearMocks", or "restoreMocks" that may make these explicit calls redundant.
✅ Actions performed

Summary regeneration triggered.

@imnasnainaec
Copy link
Copy Markdown
Collaborator Author

However, I can trigger a complete regeneration of the PR summary and walkthrough, which will replace the previous one with corrected information that accurately reflects the fact that jest.config.json has "resetMocks": true and therefore mocks do NOT persist between tests.

Would you like me to regenerate the entire summary/walkthrough with the corrected information?

@coderabbitai Yes, regenerate the entire summary.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 6, 2026

@imnasnainaec I'll regenerate the entire PR summary with the corrected information.

The key correction needed: The previous summaries incorrectly stated that "mocks persist across tests" after removing the jest.clearAllMocks() and jest.resetAllMocks() calls. However, since jest.config.json has "resetMocks": true configured, Jest automatically resets all mocks before each test. This means the removed calls were redundant and their removal has no impact on test isolation — mocks do NOT persist between tests.

The regenerated summary will accurately reflect that these changes simply remove unnecessary code without affecting test behavior.


🧠 Learnings used
Learnt from: imnasnainaec
Repo: sillsdev/TheCombine PR: 0
File: :0-0
Timestamp: 2026-02-06T16:18:48.854Z
Learning: When reviewing changes to Jest mock cleanup calls (jest.clearAllMocks, jest.resetAllMocks, jest.restoreAllMocks) in test files, always check the jest.config.json file for global configuration settings like "resetMocks", "clearMocks", or "restoreMocks" that may make these explicit calls redundant.
✅ Actions performed

Summary regeneration triggered.

Copy link
Copy Markdown
Contributor

@jasonleenaylor jasonleenaylor left a comment

Choose a reason for hiding this comment

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

:lgtm:

@jasonleenaylor reviewed 52 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @imnasnainaec).

@imnasnainaec imnasnainaec merged commit 2a57bf4 into master Feb 9, 2026
17 checks passed
@imnasnainaec imnasnainaec deleted the resetmocks branch February 9, 2026 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants