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

Jest global setup does not set a global #5424

Closed
vijayst opened this issue Jan 30, 2018 · 7 comments
Closed

Jest global setup does not set a global #5424

vijayst opened this issue Jan 30, 2018 · 7 comments

Comments

@vijayst
Copy link

vijayst commented Jan 30, 2018

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

What is the current behavior?
Not able to set a global from globalSetup.js

If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can yarn install and yarn test.

https://repl.it/@vijayst/CornsilkHonorableKakapo

What is the expected behavior?
the session key (global.sessionKey) should be available in the tests!

Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.

latest jest version - 22.1.4
Mac Sierra High, yarn 1.3

@xfumihiro
Copy link
Contributor

The globals are "sandboxed" between test suites by design.
For your use case, filing the sessionKey and access it in each tests will work.
See this guide

@thymikee thymikee closed this as completed Feb 5, 2018
@idangozlan
Copy link

@xfumihiro if so, is there anyway to create DB connection and share it between all of the test files or it should be done by connection every file to the DB again and again?

@xfumihiro
Copy link
Contributor

@idangozlan sharing states between tests is an anti-pattern.
DB connections are pooled in production anyway, so I don't see why not do the same in test.

@idangozlan
Copy link

@xfumihiro
On what phase do you recommend seeding the test DB? At the beginning of the Jest run / each test suite/file?

@xfumihiro
Copy link
Contributor

@idangozlan Again, I think it's bad practice to couple tests with states(data). Best having a fresh state on every test suite.

@idangozlan
Copy link

idangozlan commented Feb 6, 2018 via email

@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.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants