Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(jest): enable clearMocks #18779

Merged
merged 4 commits into from
Nov 15, 2022
Merged

refactor(jest): enable clearMocks #18779

merged 4 commits into from
Nov 15, 2022

Conversation

JamieMagee
Copy link
Contributor

@JamieMagee JamieMagee commented Nov 5, 2022

Changes

  • Sets clearMocks1 in jest.config.ts (equivalent to calling jest.clearAllMocks2 before each test)
  • Removes any explicit calls to jest.clearAllMocks
  • Fixes tests that were relying on faulty mock counts

This automatically clears mock calls, instances, contexts and results before every test. This makes it more difficult to write tests which rely on each other.

Context

#18768

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please tick one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests but ran on a real repository, or
  • Both unit tests + ran on a real repository

Footnotes

  1. https://jestjs.io/docs/configuration#clearmocks-boolean

  2. https://jestjs.io/docs/jest-object#jestclearallmocks

@JamieMagee JamieMagee marked this pull request as ready for review November 15, 2022 05:55
@JamieMagee JamieMagee merged commit 92eb220 into main Nov 15, 2022
@JamieMagee JamieMagee deleted the refactor/jest-clear-mocks branch November 15, 2022 06:46
@renovate-release
Copy link
Collaborator

🎉 This PR is included in version 34.25.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants