How to use Node.js global variable in mocha tests
I have found a solution that works for me by using Mocha hooks to set global variable
just for testing:
// setup.test.js
import MyFunc from '../helpers/my-func'
before((done) => {
MyFunc.then((variable) => {
global.variable = variable
done()
})
})
We can use the global.variable
in the test just like in the real code.