-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
How can I set a global variable (i.e an access token) via globalSetup? #7601
Comments
You can store it in your file system so that it's available for all tests. You can also run a pre test script that will populate and env variable and use that inside. There is a bunch of possibilities out there but Jest doesn't have a dedicated API to make this use case easier. Closing as this is not a help forum. |
globalSetup seems exactly like the place this would be done. The fact that it can't seems like a limitation. |
However, we have discussed having |
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. |
I know this has been asked before but I wasn't able to find an answer..
in my case I need to login to some API and get an access token that all the other tests can use / rely on to make the subsequent calls.
I setup a globalSetup option in my package.json where the function is being called successfully and calling the API... however I can't seem to set the returned access token to global and use it from other files, it just fails silently.
Reading through other answers I saw references to using setupFiles or beforeAll, but that doesn't help my case as they're run before each test or before each file respectively, I want to be able to run it once per setup and use it across multiple files and tests.
The text was updated successfully, but these errors were encountered: