@elise_daugherty
To test globals with Mocha.js, you can use the global
object to access and test global variables. Here's an example:
1 2 3 4 5 6 7 8 9 10 11 |
const assert = require('chai').assert; describe('Globals', function() { it('should have a global variable', function() { assert.isDefined(global.myGlobalVariable); }); it('should have a global function', function() { assert.isFunction(global.myGlobalFunction); }); }); |
1 2 3 4 5 |
global.myGlobalVariable = 'Hello, world!'; global.myGlobalFunction = function() { return 'This is a global function.'; }; |
1
|
$ mocha globals.test.js |
This will run the tests in the globals.test.js file and check whether the global variable and function are defined as expected.