Test your lightning
components using
Lightning Testing Service
- Rahul Malhotra
About Me
 Software Engineer Trainee & a part of Center of
Excellence Team at SaaSfocus
 Independent Salesforce Consultant
 Blogger and YouTuber at SFDC Stop
Today’s Agenda
 Need of testing our Lightning Component
 Introduction to Lightning Testing Service
 Jasmine & Mocha – Understanding syntax
 Live Demo - Lightning Testing Service
 Considerations for Lightning Testing Service
 Available resources to learn LTS
 Q & A
Need for Testing Lightning Components
 With the introduction of Salesforce Lightning, we started to keep data at the
client side
 This approach is necessary to reduce the number of server calls and provide a
rich User Experience to customer
 Salesforce introduced methods and actions to promote storing data at client
side cache to reduce server calls. For Ex:- Storable Actions
 This made our lightning components more responsible for handling data
 To make sure our application or component work properly with different
variety of input data, testing is important
Lightning Testing Service – An
Introduction
 Lightning Testing Service (LTS) is a set of tools and services that let you create
test suites for your lightning components using standard JavaScript
frameworks, such as Jasmine and Mocha
 At present, Salesforce provides wrappers for Jasmine and Mocha testing
framework however if you like any other framework, you can write a wrapper
for it too by yourself
 LTS provides utilities specific to lightning component framework to test
behavior specific to lightning components
 You can install LTS using Salesforce DX commands or it is also available as an
unmanaged package. You can find the latest releases of LTS on the releases
page on GitHub and install directly from there
Jasmine & Mocha – Understanding Syntax
/**
* This is a 'hello world' Jasmine test spec
*/
describe("A simple passing test",
function() {
it("checks that true is always true",
function() {
expect(true).toBe(true);
});
});
/**
* This is a 'hello world' Mocha test
*/
var assert = require('assert');
describe('Test the nature of truth',
function() {
describe('A simple passing test', function() {
it('checks that true is always true',
function() {
assert.equal(true, true);
});
});
});
Jasmine Mocha
It’s Time to Code
Considerations for Lightning Testing
Service
 Data inserted in the org while testing is not rolled back or deleted
automatically
 In some scenarios, you have to make changes in your existing lightning
component to make it ready to be used for testing
 Presently, Salesforce has provided wrappers for Jasmine and Mocha
Framework however, if you want to use any other testing framework, you are
free to use it but you have to write your own wrapper for that.
Resources
 Documentation:- https://forcedotcom.github.io/LightningTestingService/
 GitHub Repository:- https://github.com/forcedotcom/LightningTestingService
 Salesfoce Blog:- https://developer.salesforce.com/blogs/2018/04/getting-
started-with-the-lightning-testing-service.html
 SFDC Stop:- https://sfdcstop.blogspot.com/2018/05/lightningtestingservice.html
Q & A
Thank You
 GitHub Repository Link:-
https://github.com/rahulmalhotra/LightningTestingService
 My Twitter Handle:- @rahulcoder
 Blog:- https://sfdcstop.blogspot.com
 YouTube Channel:- https://www.youtube.com/c/SFDCStop
 Salesforce Chatter:- http://bit.ly/rahulforce

Lightning Testing Service

  • 1.
    Test your lightning componentsusing Lightning Testing Service - Rahul Malhotra
  • 2.
    About Me  SoftwareEngineer Trainee & a part of Center of Excellence Team at SaaSfocus  Independent Salesforce Consultant  Blogger and YouTuber at SFDC Stop
  • 3.
    Today’s Agenda  Needof testing our Lightning Component  Introduction to Lightning Testing Service  Jasmine & Mocha – Understanding syntax  Live Demo - Lightning Testing Service  Considerations for Lightning Testing Service  Available resources to learn LTS  Q & A
  • 4.
    Need for TestingLightning Components  With the introduction of Salesforce Lightning, we started to keep data at the client side  This approach is necessary to reduce the number of server calls and provide a rich User Experience to customer  Salesforce introduced methods and actions to promote storing data at client side cache to reduce server calls. For Ex:- Storable Actions  This made our lightning components more responsible for handling data  To make sure our application or component work properly with different variety of input data, testing is important
  • 5.
    Lightning Testing Service– An Introduction  Lightning Testing Service (LTS) is a set of tools and services that let you create test suites for your lightning components using standard JavaScript frameworks, such as Jasmine and Mocha  At present, Salesforce provides wrappers for Jasmine and Mocha testing framework however if you like any other framework, you can write a wrapper for it too by yourself  LTS provides utilities specific to lightning component framework to test behavior specific to lightning components  You can install LTS using Salesforce DX commands or it is also available as an unmanaged package. You can find the latest releases of LTS on the releases page on GitHub and install directly from there
  • 6.
    Jasmine & Mocha– Understanding Syntax /** * This is a 'hello world' Jasmine test spec */ describe("A simple passing test", function() { it("checks that true is always true", function() { expect(true).toBe(true); }); }); /** * This is a 'hello world' Mocha test */ var assert = require('assert'); describe('Test the nature of truth', function() { describe('A simple passing test', function() { it('checks that true is always true', function() { assert.equal(true, true); }); }); }); Jasmine Mocha
  • 7.
  • 8.
    Considerations for LightningTesting Service  Data inserted in the org while testing is not rolled back or deleted automatically  In some scenarios, you have to make changes in your existing lightning component to make it ready to be used for testing  Presently, Salesforce has provided wrappers for Jasmine and Mocha Framework however, if you want to use any other testing framework, you are free to use it but you have to write your own wrapper for that.
  • 9.
    Resources  Documentation:- https://forcedotcom.github.io/LightningTestingService/ GitHub Repository:- https://github.com/forcedotcom/LightningTestingService  Salesfoce Blog:- https://developer.salesforce.com/blogs/2018/04/getting- started-with-the-lightning-testing-service.html  SFDC Stop:- https://sfdcstop.blogspot.com/2018/05/lightningtestingservice.html
  • 10.
  • 11.
    Thank You  GitHubRepository Link:- https://github.com/rahulmalhotra/LightningTestingService  My Twitter Handle:- @rahulcoder  Blog:- https://sfdcstop.blogspot.com  YouTube Channel:- https://www.youtube.com/c/SFDCStop  Salesforce Chatter:- http://bit.ly/rahulforce