@filiberto
To use a Node.js global variable in Mocha tests, you can simply set the variable as a global variable in your test file or in a separate file that is required by your test file.
Here is an example:
1
|
global.myGlobalVariable = 'Hello, world!'; |
1 2 3 4 5 6 7 |
require('./globalVariable.js'); describe('My test suite', function() { it('should access the global variable', function() { console.log(myGlobalVariable); // Output: Hello, world! }); }); |
1
|
mocha test.js |
In this example, the global variable myGlobalVariable
set in globalVariable.js
is accessible in the Mocha test file test.js
.
This way, you can use Node.js global variables in your Mocha tests by setting them as global variables and requiring them in your test files.