Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Expose helper via an public aura:method function in your abstract component's `testHelperController.js`:
- ```
- getHelper: function(component, event, helper) {
- if ( $T ) {
- return helper;
- } else {
- throw new Error('API is only supported in test context');
- }
- }
- ```
- testHelper.cmp:
- ```
- <aura:component abstract="true" extensible="true">
- <aura:method name="getHelper"/>
- </aura:component>
- ```
- Embed it in your componentToTest.cmp:
- ```
- <aura:component extends="testHelper">
- <lightning:button onclick="{!c.buttonClick}"/>
- </aura:component>
- ```
- buttonClick calls componentToTestController.js
- ```
- buttonClick: function(component, event, helper) {
- var string = helper.concatStrings(['fizz','buzz'], ', ')
- }
- ```
- And it's componentToTestHelper.js where code actually is:
- ```
- concatStrings : function(strings, delim) {
- var string = strings.join(delim)
- return string
- }
- ```
- And then call it in your test:
- ```
- describe("componentToTest helpers test", function(){
- describe('test componentToTest helper method "concatStrings"', function() {
- it('Tests how strings are concatenated', function(done) {
- $T.createComponent("c:componentToTest", {}, true).then(function(component) {
- var string = component.getHelper().concatStrings(['foo','baz','qux'],', ')
- expect(string).toBe('foo, baz, qux')
- done()
- ```
Add Comment
Please, Sign In to add comment