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

restoreMocks doesn't reset the mocks from the last test if mocking jsdom in a beforeEach #5790

Closed
lukeapage opened this issue Mar 13, 2018 · 5 comments
Labels

Comments

@lukeapage
Copy link
Contributor

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

https://repl.it/@lukeapage/Fails-based-on-order

In the above repl you need to make sure the tests run the files in the right order - one then two. When two fails it goes to the begining, the tests pass and then its difficult to reproduce.

If in one test file you mock jsdom in a beforeEach and in a second file use the jsdom function unmocked, then you end up with the mock function.

I tried to make a test case not using jsdom and it was fine.

Within one file its fine.

If the last test in a file doesn't have a beforeEach adding the mock, its also fine.

e.g. the restoreMocks option is behaving differently to adding jest.restoreAllMocks() in a afterEach

What is the expected behavior?

restoreMocks: true will restore all mocks

Please provide your exact Jest configuration
Run npx envinfo --preset jest in your project directory and paste the
results here

See the repl above

@lukeapage
Copy link
Contributor Author

Is the cause that restoreAllMocks is called in a global beforeEach rather than afterEach and jsdom survives between test files?

@lukeapage
Copy link
Contributor Author

I moved it to a afterEach in my own project (where we have 900 suites and random failures) and it seems fine. But I don't know why its in beforeEach so I'll wait to hear from someone before I send a patch.

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Feb 25, 2022
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@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 Apr 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant