{"id":6419,"date":"2018-03-10T15:11:19","date_gmt":"2018-03-10T20:11:19","guid":{"rendered":"https:\/\/www.jitendrazaa.com\/blog\/?p=6419"},"modified":"2018-03-10T15:16:38","modified_gmt":"2018-03-10T20:16:38","slug":"introduction-to-lightning-test-services-with-jasmine","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/introduction-to-lightning-test-services-with-jasmine\/","title":{"rendered":"Introduction to Lightning Test Services with Jasmine"},"content":{"rendered":"<p style=\"text-align: justify;\">In previous post, we discussed <a href=\"https:\/\/www.jitendrazaa.com\/blog\/webtech\/getting-started-with-jasmine-test-framework\/\">what is Jasmine and simple hello world program to see how it works<\/a>. In this blog post, we will discuss how Jasmine can be used in Salesforce to test Lightning Component&#8217;s Javascript code.<\/p>\n<p style=\"text-align: justify;\">Note : Everything we are discussing here is completely covered as part of <a href=\"https:\/\/www.youtube.com\/watch?v=YGeJjDRiqMg\">Live coding in Apex Salesforce Saturday<\/a> organized by <a href=\"http:\/\/amitsalesforce.blogspot.com\/\">Amit<\/a>. Would like to thank <a href=\"http:\/\/cloudyworlds.blogspot.com\/\">Mohith<\/a> for his support and answers during the demo. It also shows\u00a0<strong>How SalesforceDX\u00a0<\/strong>can be used daily by developers to perform development.<\/p>\n<p style=\"text-align: justify;\"><strong>Jasmine<\/strong> and <strong>Mocha<\/strong> support is provided as a part of <strong>Lightning Test Service (LTS)<\/strong> by Salesforce. Jasmine and Mocha, both are well known and industry wide solution accepted in Javascript world. of course, Salesforce don&#8217;t want to stay behind in terms of its offering to developers thats why we have new baby in town &#8211; <strong>Lightning Test Service (LTS)<\/strong>.<!--more--><\/p>\n<p style=\"text-align: justify;\">You can install\u00a0<strong>Lightning Test Service (LTS)\u00a0<\/strong>in your org as a part of <a href=\"https:\/\/github.com\/forcedotcom\/LightningTestingService\/releases\">unamanged package from here<\/a>. You can also install <strong>Lightning Test Service<\/strong> in <a href=\"http:\/\/www.jitendrazaa.com\/blog\/tag\/sfdx\/\">SFDX<\/a> using command<\/p>\n<pre>sfdx force:lightning:test:install<\/pre>\n<p style=\"text-align: justify;\">Once Jasmine is installed, you can navigate in your browser to open\u00a0<strong>Jasmine\u00a0<\/strong>test runner page using URL\u00a0<em>https:\/\/&lt;YourDomain&gt;.lightning.force.com\/c\/jasmineTests.app<\/em><\/p>\n<p><strong>SFDX Command to open Jasmine Test runner in Salesforce<\/strong><\/p>\n<pre>sfdx force:org:open -p \/c\/jasmineTests.app<\/pre>\n<p style=\"text-align: justify;\">Let&#8217;s consider below Lightning component to be used by\u00a0<strong>Lightning Test Service (LTS)\u00a0<\/strong><\/p>\n<figure id=\"attachment_6424\" aria-describedby=\"caption-attachment-6424\" style=\"width: 1453px\" class=\"wp-caption aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"wp-image-6424 size-full\" src=\"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Lightning-Component-using-DataTable-and-Lightning-Test-Service.gif?resize=1453%2C668&#038;ssl=1\" alt=\"Lightning Component using DataTable and Lightning Test Service\" width=\"1453\" height=\"668\" \/><figcaption id=\"caption-attachment-6424\" class=\"wp-caption-text\">Lightning Component using DataTable and Lightning Test Service<\/figcaption><\/figure>\n<p style=\"text-align: justify;\">This Lightning Component uses\u00a0<strong>lightning:datatable\u00a0<\/strong>component and populates it on basis of input provided.<br \/>\n<script src=\"https:\/\/gist.github.com\/JitendraZaa\/8c09eeba0b5d5c5a4c1c9d36594e6fae.js\"><\/script><br \/>\nNow we need to create a Javascript file containing\u00a0<strong>Jasmine test method\u00a0<\/strong>and upload it as a static resource.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/JitendraZaa\/47ff446258f861f6f8f8896593d471ec.js\"><\/script><\/p>\n<p style=\"text-align: justify;\">Once, static resource is uploaded in Salesforce, we need to add reference of this static resource in\u00a0<strong>JasmineTests.app<\/strong>\u00a0. In our case, static resource name is <em>JasmineTestDatatable<\/em>.\u00a0 This Test runner application comes as part of\u00a0<strong>Lightning Test Service.\u00a0<\/strong>Same way, MochaTest runner app also comes as part of <strong>LTS<\/strong>.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/JitendraZaa\/bee4d17d3cefcf749592e39d64a54087.js\"><\/script><\/p>\n<p style=\"text-align: justify;\">It is time to open Jasmine Test runner using <em>URL\u00a0https:\/\/&lt;YourDomain&gt;.lightning.force.com\/c\/jasmineTests.app<\/em>. We would be able to see below output<\/p>\n<figure id=\"attachment_6423\" aria-describedby=\"caption-attachment-6423\" style=\"width: 641px\" class=\"wp-caption aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-6423\" src=\"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Salesforce-Lightning-Test-Service-LTS-Output.png?resize=641%2C250&#038;ssl=1\" alt=\"Salesforce Lightning Test Service (LTS) Output\" width=\"641\" height=\"250\" srcset=\"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Salesforce-Lightning-Test-Service-LTS-Output.png?w=641&amp;ssl=1 641w, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Salesforce-Lightning-Test-Service-LTS-Output.png?resize=300%2C117&amp;ssl=1 300w\" sizes=\"auto, (max-width: 641px) 100vw, 641px\" \/><figcaption id=\"caption-attachment-6423\" class=\"wp-caption-text\">Salesforce Lightning Test Service (LTS) Output<\/figcaption><\/figure>\n<p><strong>Youtube Video of Lightning Test Service (LTS)<\/strong><\/p>\n<p><iframe loading=\"lazy\" title=\"Lightning Testing Service  (LTS)\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/YGeJjDRiqMg?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Complete Source code and video of using Lightning Datatable Component and  Jasmine in Salesforce<\/p>\n","protected":false},"author":1,"featured_media":6428,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9],"tags":[435,311,437,438,415,304,212],"class_list":["post-6419","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-salesforce","tag-bdd","tag-lightning-component","tag-lightning-test-service","tag-lts","tag-sfdx","tag-testing","tag-video-tutorial"],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Lightning-Testing-Service-LTS.png?fit=1365%2C493&ssl=1","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":5796,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/lightning-data-services-standard-controller-for-lightning-components\/","url_meta":{"origin":6419,"position":0},"title":"Lightning Data Service &#8211; Standard Controller for Lightning Components","author":"Jitendra","date":"July 22, 2017","format":false,"excerpt":"Best Practices for Salesforce Lightning Component. How Lightning Data Service can improve Lightning Component performance and solve inconsistent data problem without writing single line of Apex code. Demo source code, image and slides included.","rel":"","context":"In &quot;Apex&quot;","block_context":{"text":"Apex","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/apex\/"},"img":{"alt_text":"Salesforce Lightning Data Services","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/07\/Salesforce-Lightning-Data-Services.png?fit=1045%2C395&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/07\/Salesforce-Lightning-Data-Services.png?fit=1045%2C395&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/07\/Salesforce-Lightning-Data-Services.png?fit=1045%2C395&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/07\/Salesforce-Lightning-Data-Services.png?fit=1045%2C395&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":5539,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/lightning-component-code-review-using-cli-video\/","url_meta":{"origin":6419,"position":1},"title":"Lightning component code review using CLI &#8211; Video","author":"Jitendra","date":"June 15, 2016","format":false,"excerpt":"Video tutorial explaining how we can use Lightning CLI to identify possible issues and enhancements needed for Lightning Component and enabling it for Locker Service","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/img.youtube.com\/vi\/f1Zn61WYMZM\/0.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":6176,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/lookup-component-in-salesforce-lightning\/","url_meta":{"origin":6419,"position":2},"title":"Lookup component in Salesforce Lightning","author":"Jitendra","date":"July 6, 2017","format":false,"excerpt":"Salesforce Lightning component in plain JavaScript and SLDS with complete source code","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Salesforce Lightning Lookup Component","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/07\/Salesforce-Lightning-Lookup-Component.png?fit=978%2C285&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/07\/Salesforce-Lightning-Lookup-Component.png?fit=978%2C285&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/07\/Salesforce-Lightning-Lookup-Component.png?fit=978%2C285&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/07\/Salesforce-Lightning-Lookup-Component.png?fit=978%2C285&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":5562,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/summer-16-top-features\/","url_meta":{"origin":6419,"position":3},"title":"Salesforce Summer 16 &#8211; My favorite top 20 features","author":"Jitendra","date":"June 28, 2016","format":false,"excerpt":"List of Salesforce Summer 16 features","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"User Switcher in Salesforce Summer 16","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/06\/User-Switcher-in-Salesforce-Summer-16.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":6252,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-path-read-only-lightning-component\/","url_meta":{"origin":6419,"position":4},"title":"Salesforce Path &#8211; Read Only Lightning Component","author":"Jitendra","date":"September 17, 2017","format":false,"excerpt":"Chevron Component build in Lightning with Same look and feel as of Salesforce Path in read only mode","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Read only Path (Chevron) Component in Salesforce Lightning","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/09\/Chevron-Lightning-Component-Salesforce.gif?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/09\/Chevron-Lightning-Component-Salesforce.gif?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/09\/Chevron-Lightning-Component-Salesforce.gif?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/09\/Chevron-Lightning-Component-Salesforce.gif?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":6017,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/export-or-print-code-review-feedback-generated-by-salesforce-lightning-cli\/","url_meta":{"origin":6419,"position":5},"title":"Export or print code review feedback generated by Salesforce Lightning CLI","author":"Jitendra","date":"May 2, 2017","format":false,"excerpt":"How to print or export code review feedback report generated by Salesforce Lightning CLI tool","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Export Salesforce Lightning CLI code review report","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/05\/Salesforce-Lightning-CLI-code-review-report.png?fit=1200%2C710&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/05\/Salesforce-Lightning-CLI-code-review-report.png?fit=1200%2C710&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/05\/Salesforce-Lightning-CLI-code-review-report.png?fit=1200%2C710&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/05\/Salesforce-Lightning-CLI-code-review-report.png?fit=1200%2C710&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/05\/Salesforce-Lightning-CLI-code-review-report.png?fit=1200%2C710&ssl=1&resize=1050%2C600 3x"},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/6419","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=6419"}],"version-history":[{"count":2,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/6419\/revisions"}],"predecessor-version":[{"id":6427,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/6419\/revisions\/6427"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media\/6428"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=6419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=6419"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=6419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}