Created
August 7, 2017 20:50
-
-
Save yury-sannikov/a72fc975662c55eec7ce6ef7b54065d9 to your computer and use it in GitHub Desktop.
mocha-aura Apex & Callbacks
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 { apexCallFactory, apexErrorResult, apexSuccessResult, componentFactory } = require('mocha-aura/aura') | |
const helper = require('path/to/aura/helper') | |
describe('Apex Call Test', () => { | |
it('should set component v.object to Apex result', apexTest(false)); | |
it('should set v.error if Apex call failed', apexTest(true)); | |
}) | |
function apexTest(isError) { | |
return () => { | |
const result = {items: []} | |
// Create apexCallFactory with error or success result depending on test parameter | |
const confirmOrder = apexCallFactory(isError ? apexErrorResult('err_msg') | |
: apexSuccessResult(result) | |
) | |
// Create aura component, set v.confirmOrder to Apex call object and v.object to null | |
const component = componentFactory({confirmOrder, object: null }); | |
// Call real helper code with our mock component | |
helper.loadApexData(component); | |
if (isError) { | |
// In case of error helper method should set v.error value | |
expect(component.get('v.error')).to.equal('err_msg'); | |
return; | |
} | |
// In case of success helper method should set v.object to a return value | |
expect(component.get('v.object')).to.equal(result); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment