Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to do actual unit testing in Lightning Testing Service

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');


<aura:component abstract="true" extensible="true">
 <aura:method name="getHelper"/>

Embed it in your componentToTest.cmp:

<aura:component extends="testHelper">
  <lightning:button onclick="{!c.buttonClick}"/>

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')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment