Skip to content

Instantly share code, notes, and snippets.

@yury-sannikov
Last active August 6, 2017 15:41
Show Gist options
  • Save yury-sannikov/7460daa38c247d61f66d473b1695546c to your computer and use it in GitHub Desktop.
Save yury-sannikov/7460daa38c247d61f66d473b1695546c to your computer and use it in GitHub Desktop.
mocha-aura globals
const { auraFactory, eventFactory } = require('mocha-aura/aura')
describe('Component Controller', () => {
let sandbox, clock;
before(() => {
global.$A = auraFactory({
// Define all your labels you're using in a test suite
'$Label.c.My_Label': 'My_Label',
// Define all global events
'e.c:ShowComponentEvent': eventFactory()
});
// You might create a sinon sandbox here
sandbox = sinon.sandbox.create();
// Add this if you need to test setTimeout & setInterval in your code
clock = sinon.useFakeTimers();
// Define a global objects your tested code might access during test suite
global.document = { title: '' }
global.window = {location: {hash: '#'}}
})
after(() => {
// Do not forget to delete all objects you've added
['$A', 'document', 'window'].forEach(prop => delete global[prop]);
// Restore sandbox and fake timers
sandbox.restore();
clock.restore();
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment