Guest User

Untitled

a guest
Apr 25th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. Expose helper via an public aura:method function in your abstract component's `testHelperController.js`:
  2. ```
  3. getHelper: function(component, event, helper) {
  4. if ( $T ) {
  5. return helper;
  6. } else {
  7. throw new Error('API is only supported in test context');
  8. }
  9. }
  10. ```
  11. testHelper.cmp:
  12. ```
  13. <aura:component abstract="true" extensible="true">
  14. <aura:method name="getHelper"/>
  15. </aura:component>
  16. ```
  17.  
  18. Embed it in your componentToTest.cmp:
  19. ```
  20. <aura:component extends="testHelper">
  21. <lightning:button onclick="{!c.buttonClick}"/>
  22. </aura:component>
  23. ```
  24.  
  25. buttonClick calls componentToTestController.js
  26. ```
  27. buttonClick: function(component, event, helper) {
  28. var string = helper.concatStrings(['fizz','buzz'], ', ')
  29. }
  30. ```
  31. And it's componentToTestHelper.js where code actually is:
  32. ```
  33. concatStrings : function(strings, delim) {
  34. var string = strings.join(delim)
  35. return string
  36. }
  37. ```
  38.  
  39. And then call it in your test:
  40. ```
  41. describe("componentToTest helpers test", function(){
  42. describe('test componentToTest helper method "concatStrings"', function() {
  43. it('Tests how strings are concatenated', function(done) {
  44. $T.createComponent("c:componentToTest", {}, true).then(function(component) {
  45. var string = component.getHelper().concatStrings(['foo','baz','qux'],', ')
  46. expect(string).toBe('foo, baz, qux')
  47. done()
  48. ```
Add Comment
Please, Sign In to add comment