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

TypeError: jest.restoreAllMocks is not a function #5059

Closed
jeff-lau opened this issue Dec 12, 2017 · 7 comments
Closed

TypeError: jest.restoreAllMocks is not a function #5059

jeff-lau opened this issue Dec 12, 2017 · 7 comments

Comments

@jeff-lau
Copy link

Using the latest version of jest (21.2.1), calls to

jest.restoreAllMocks()

Is failing with

TypeError: jest.restoreAllMocks is not a function

This maybe inside a test, or inside the afterEach.
However, it seems to work inside an afterAll?

The problem seems to have been mentioned and supposedly resolved here:
#4436

However, I created a new app using create-react-app, added a jest.restoreAllMock in the test, and it fails with the same error.

Is anyone else hitting this problem?

@Rob-Leggett
Copy link

+1

@SimenB
Copy link
Member

SimenB commented Dec 12, 2017

I'm unable to reproduce this, can you give a snippet which reproduces?

@jeff-lau
Copy link
Author

jeff-lau commented Dec 12, 2017

Thank you for looking into this @SimenB

I updated app.test.js to the following:

afterEach(() => {
	jest.restoreAllMocks();
});

it('renders without crashing', () => {
  const div = document.createElement('div');
  ReactDOM.render(<App />, div);
});

If I change afterEach to afterAll, the test would pass.

@SimenB
Copy link
Member

SimenB commented Dec 12, 2017

I still cannot reproduce this... Are you sure you are on latest version of jest?

This is my repro case: https://gist.github.com/anonymous/7e1f26019551ec8acdb287c4cf89ce27

I get a warning from react because of missing raf (can be fixed by jest@test, but no issues either way), but the test passes and does not crash.

@SimenB
Copy link
Member

SimenB commented Dec 14, 2017

Closing until we can reproduce this. Happy to reopen if we can, of course 🙂

@SimenB SimenB closed this as completed Dec 14, 2017
@jeff-lau
Copy link
Author

thanks @SimenB.

Looks like you are right, at least for the create-react-app example.

The actual project where this is happening does seem to have the correct version though, so I will need to investigate this further.

thanks for your help.

@github-actions
Copy link

This issue 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

No branches or pull requests

3 participants