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 resetMocks #18934

Closed
wants to merge 2 commits into from
Closed

Conversation

JamieMagee
Copy link
Contributor

Changes

  • Sets resetMocks1 in jest.config.ts (equivalent to calling jest.resetAllMocks2 before each test)
  • Removes any explicit calls to jest.resetAllMocks
  • Fixes tests that were relying on mocks from other tests

This automatically clears mock implementations or return values before every test. This makes it more difficult to write tests which rely on each other.

Tests still to fix:

  • ...

Context

Second part of #18768
Follow-up from #18779

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#resetmocks-boolean

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

Copy link
Member

@viceice viceice left a comment

Choose a reason for hiding this comment

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

  1. This allows users to be more lazy when writing tests. 😕
  2. We do some static mocking (module scope), which is now broken

@rarkins
Copy link
Collaborator

rarkins commented Dec 17, 2022

What's the path forward for this?

@JamieMagee JamieMagee force-pushed the refactor/jest-reset-mocks branch from 512da8b to d915de9 Compare December 24, 2022 06:06
@JamieMagee JamieMagee force-pushed the refactor/jest-reset-mocks branch from d915de9 to a493b4d Compare April 10, 2023 02:25
@JamieMagee JamieMagee mentioned this pull request Apr 10, 2023
6 tasks
@JamieMagee JamieMagee force-pushed the refactor/jest-reset-mocks branch 2 times, most recently from 811a18b to 91b472e Compare April 12, 2023 05:14
@HonkingGoose
Copy link
Collaborator

@JamieMagee might be good to pull in the latest changes from main, because @zharinov changed a lot of test-related stuff.

@JamieMagee JamieMagee force-pushed the refactor/jest-reset-mocks branch from 91b472e to 0e82a63 Compare June 19, 2023 04:16
@rarkins rarkins closed this Sep 16, 2023
@rarkins rarkins deleted the refactor/jest-reset-mocks branch September 19, 2023 13:20
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 20, 2023
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