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

Restore fake timers after resetting mocks #2467

Merged
merged 1 commit into from Feb 27, 2017

Conversation

thymikee
Copy link
Collaborator

Summary
Fake timers are implemented as mocks. When defined in package.json with "timers": "fake" they set up mocking functions and work properly. However when combined with "resetMocks": true they're not restored and completely gone.

This is just a naive fix to the problem, but we can think of a better solution where we're actually in control of resetting mocks instead of wiping them out. Not sure how to approach it though.

PR includes integration test with these conflicting options.

Fixes #2455.

Test plan
Integration test

@codecov-io
Copy link

Current coverage is 87.53% (diff: 100%)

Merging #2467 into master will not change coverage

@@             master      #2467   diff @@
==========================================
  Files            40         40          
  Lines          1653       1653          
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
  Hits           1447       1447          
  Misses          206        206          
  Partials          0          0          

Powered by Codecov. Last update cf1f00a...cf6917a

@thymikee thymikee mentioned this pull request Jan 26, 2017
@thymikee thymikee closed this Feb 19, 2017
@thymikee thymikee deleted the timers-with-resetMocks branch February 19, 2017 16:29
@thymikee thymikee restored the timers-with-resetMocks branch February 19, 2017 16:32
@thymikee thymikee reopened this Feb 19, 2017
@cpojer
Copy link
Member

cpojer commented Feb 27, 2017

@thymikee what's the status of this PR?

@thymikee
Copy link
Collaborator Author

It's finished, and should fix the problem with timers along with "reset": true config.

For this:

This is just a naive fix to the problem, but we can think of a better solution where we're actually in control of resetting mocks instead of wiping them out. Not sure how to approach it though.

we now have clearMocks back.

@jest-bot
Copy link
Contributor

Fails
🚫 New JS files do not have the Facebook copyright header: integration_tests/timer-resetMocks/with_resetMocks/timer_with_mock.test.js
🚫 Please ensure that 'use strict' is enabled on: integration_tests/timer-resetMocks/with_resetMocks/timer_with_mock.test.js
Warnings
⚠️ Please ensure that @flow is enabled on: integration_tests/timer-resetMocks/with_resetMocks/index.js and integration_tests/timer-resetMocks/with_resetMocks/timer_with_mock.test.js

Generated by 🚫 dangerJS

@cpojer cpojer merged commit d7673a4 into jestjs:master Feb 27, 2017
@thymikee thymikee deleted the timers-with-resetMocks branch March 23, 2017 18:30
skovhus pushed a commit to skovhus/jest that referenced this pull request Apr 29, 2017
tushardhole pushed a commit to tushardhole/jest that referenced this pull request Aug 21, 2017
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

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

Successfully merging this pull request may close these issues.

resetMocks breaks timers: "fake" config options
5 participants