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

Allow to override resetMocks and resetModules Jest configuration? #3116

Closed
jpetitcolas opened this issue Sep 12, 2017 · 9 comments
Closed

Allow to override resetMocks and resetModules Jest configuration? #3116

jpetitcolas opened this issue Sep 12, 2017 · 9 comments

Comments

@jpetitcolas
Copy link

I am wondering if you would be opened to allow overriding the resetMocks and resetModules options from Jest configuration? Currently, when trying to update them directly in the package.json such as:

{
  "jest": {
    "resetMocks": true
  }
}

I got a message telling me it is not configurable:

Out of the box, Create React App only supports overriding these Jest options:

  • collectCoverageFrom
  • coverageReporters
  • coverageThreshold
  • snapshotSerializers.

As an absent minded developer, I will always forget to restore a mock one day or another. And this parameter would save (the future) me a lot of time. Is there any particular reason to restrict these two options? Or is it just a lack waiting for a PR? :)

Related Jest documentation: https://facebook.github.io/jest/docs/en/configuration.html#resetmocks-boolean

@GAumala
Copy link
Contributor

GAumala commented Sep 12, 2017

overriding resetMocks would be a really nice feature. I wish jest would let the user configure it via a command line argument, though.

@eliw00d
Copy link

eliw00d commented Nov 29, 2017

+1 for overriding config and/or as CLI argument.

@gaearon
Copy link
Contributor

gaearon commented Jan 8, 2018

Sure, that sounds good.

@adamtowerz
Copy link

Can this issue be expanded to cover other jest configurations like "setupFiles" so it can support mocking libraries like jest-localstorage-mock?

@gaearon
Copy link
Contributor

gaearon commented Jan 11, 2018

Does setupFiles let you do something you can't put in src/setupTests.js (that's automatically executed before tests)?

@adamtowerz
Copy link

adamtowerz commented Jan 11, 2018

It doesn't provide any functionality you can't put in src/setupTests.js, but it feels like a better solution for supporting libraries that act as Jest plugins than to write a new file to import these plugins. It is also the solution Jest natively supports, so if it is possible to just pass on the configuration to Jest I don't see a reason not to support the option.

@gaearon
Copy link
Contributor

gaearon commented Jan 14, 2018

but it feels like a better solution for supporting libraries that act as Jest plugins than to write a new file to import these plugins

I see your point but I feel that since it's perfectly possible to use the global conventional file, and we already support it, this doesn't really add value.

resetMocks and resetModules still sounds good though.

@gaearon gaearon modified the milestones: 1.x, 2.x Jan 14, 2018
garmeeh added a commit to garmeeh/create-react-app that referenced this issue Jan 15, 2018
@garmeeh
Copy link
Contributor

garmeeh commented Jan 15, 2018

PR #3802 opened to try add this feature.

@gaearon
Copy link
Contributor

gaearon commented Jan 15, 2018

#3802

@gaearon gaearon closed this as completed Jan 15, 2018
@gaearon gaearon modified the milestones: 2.x, 2.0.0 Jan 15, 2018
akstuhl pushed a commit to akstuhl/create-react-app that referenced this issue Mar 15, 2018
zmitry pushed a commit to zmitry/create-react-app that referenced this issue Sep 30, 2018
@lock lock bot locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants