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

beforeAll, beforeEach, afterEach, afterAll do not work from setupFilesAfterEnv #70

Open
michael42 opened this issue Feb 11, 2023 · 2 comments

Comments

@michael42
Copy link

michael42 commented Feb 11, 2023

Hi there, thanks for the great project!

I consider jest's partial test isolation to be more trouble than it's worth and would rather switch to jest-light-runner, don't mess around with globals (expect with jest.spyOn) and use the built-in jest features to revert these changes after every test.

However, it seems that the resetMocks and restoreMocks config option no longer works with jest-light-runner (probably a separate bug), so I tried working around that using a custom setup script (with setupFilesAfterEnv).

Actual behavior

But it seems that beforeAll, beforeEach, afterEach, afterAll simply do nothing when called from such a script, for example:

setup-after-env.js:

console.log("setup-after-env")
beforeAll(() => console.log("setup beforeAll"))
beforeEach(() => console.log("setup beforeEach"))
afterEach(() => console.log("setup afterEach"))
afterAll(() => console.log("setup afterAll"))

demo.test.js:

it("should work", () => console.log("test"))

With jest-light-runner, this only prints:

setup-after-env
test

edit: Here's a minimal reproduction repo

Expected behavior

setup-after-env
setup beforeAll
setup beforeEach
test
setup afterEach
setup afterAll
@cbarceloc
Copy link

Same issue here

@nicolo-ribaudo
Copy link
Owner

@cbarceloc Would you like to submit a PR? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants