Jest global variable example

Can someone give an example of using humorous globals?

{ ... "jest": { "globals": { "__DEV__": true, } } ... } 

Do I need to specify global variables in the package.json file or create a folder with a js file in which global variables should be defined?

thanks

+15
jestjs
source share
2 answers

Yeah. You put globals in package.json. For example, here is an excerpt from the default jest response default configuration:

 "jest": { "globals": { "__DEV__": true, "__RCTProfileIsProfiling": false }, ... }, 

This will cause the variables to be available worldwide during test execution.

+29
source share

For me, using the Jest configuration file worked much better because it is the Javascript file itself, so it gives complete freedom:

After running jest --init in your folder, in the jest.config.js file that Jest does, scroll down to find:

 // A set of global variables that need to be available in all test environments // globals: {}, 

Uncomment the second line and put all your globals there.

+1
source share

All Articles