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

chore(docs): Adds clearMocks to unit-testing #26802

Closed

Conversation

AbbottSoft
Copy link

Description

Updates unit-testing.md to include the clearMocks property in jest.config.js.

The instructions in step #3 suggest setting up a globally mocked gatsby object in the __mocks__ directory at the root of the project. However, if anyone were to utilize these mocks, such as mocking the return value in a test, the state of the mocks would persist between tests, leading to unexpected outcomes. This change attempts to address this by adding the clearMocks configuration to the jest config so that developers following this tutorial will not need to manually reset the mocks on each test.

Documentation

Jest clearMocks documentation

Related Issues

Issue #26795 - Mocking gatsby in mocks not cleaning up after tests

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Sep 6, 2020
@LekoArts LekoArts added type: documentation An issue or pull request for improving or updating Gatsby's documentation and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Sep 7, 2020
@LekoArts LekoArts changed the title Adds clearMocks to unit-testing.md chore(docs): Adds clearMocks to unit-testing Sep 7, 2020
@LekoArts
Copy link
Contributor

LekoArts commented Sep 8, 2020

Hey! Thanks so much for opening a pull request!

The change you’ve proposed is not going to be accepted because this change is a question of preference and in those cases we want to stick to the defaults unless we have a specific reason not to. A lot of people (including me) choose to explicitly clear the mocks via jest.clearAllMocks() in the afterEach() hook. Feel free to change your jest-config file however we'll want to stick to the default here.

We absolutely want to have you as a contributor, so please take a look at our open issues for ideas, and please reach out to us on Twitter at @gatsbyjs with questions.

Thanks again, and we look forward to seeing more PRs from you in the future! 💪💜

@LekoArts LekoArts closed this Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation An issue or pull request for improving or updating Gatsby's documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants