Last active
August 6, 2017 15:41
-
-
Save yury-sannikov/7460daa38c247d61f66d473b1695546c to your computer and use it in GitHub Desktop.
mocha-aura globals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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