{"id":6411,"date":"2018-03-10T14:18:50","date_gmt":"2018-03-10T19:18:50","guid":{"rendered":"https:\/\/www.jitendrazaa.com\/blog\/?p=6411"},"modified":"2018-03-13T12:00:57","modified_gmt":"2018-03-13T16:00:57","slug":"getting-started-with-jasmine-test-framework","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/webtech\/getting-started-with-jasmine-test-framework\/","title":{"rendered":"Getting Started with Jasmine Test Framework"},"content":{"rendered":"<p style=\"text-align: justify;\"><strong>Jasmine<\/strong> is a Javascript Testing framework which starts with behavioral specifications as a basis for writing test cases. To put it another way, you can consider user stories as a reference for write test cases. Each user story in your project can have one or more <strong>Jasmine<\/strong> test cases.<\/p>\n<p>Majorly, Jasmine is made up of three functions<\/p>\n<ol>\n<li><strong>describe<\/strong><\/li>\n<li><strong>it<\/strong><\/li>\n<li><strong>assertions<\/strong> (expect)<\/li>\n<\/ol>\n<p style=\"text-align: justify;\">Like standard frameworks, it also has setup method and tear down methods<\/p>\n<ul>\n<li><strong>beforeEach()<\/strong> &#8211; Setup Method<\/li>\n<li><strong>afterEach()<\/strong> &#8211; Teardown Method<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">For the sake of simplicity of post, I would not discuss much in detail. However, you can navigate to <a href=\"https:\/\/github.com\/jasmine\/jasmine#installation\">official Jasmine guide<\/a> for deep dive.<!--more--><\/p>\n<h5>Download Jasmine<\/h5>\n<p style=\"text-align: justify;\">You can download latest version of <strong>Jasmine<\/strong> from <a href=\"https:\/\/github.com\/jasmine\/jasmine#installation\">here<\/a>. Once downloaded, you can extract and save <em>lib<\/em> folder in your project.<\/p>\n<h5>Simple Javascript code for Jasmine Test Framework<\/h5>\n<p style=\"text-align: justify;\">Let&#8217;s consider below Javascript code. It simply declares a person object with few properties and method to get full name and change Age.<br \/>\n<script src=\"https:\/\/gist.github.com\/JitendraZaa\/a504a06bec6cdec98750fb74d3e851ae.js\"><\/script><br \/>\nIts time to see how we can write a test method using Jasmine Framework.<br \/>\n<script src=\"https:\/\/gist.github.com\/JitendraZaa\/2f504149b4d9fac196daa24bf9de1e43.js\"><\/script><br \/>\nAbove code snippet shows how we are using <strong>describe<\/strong>, <strong>it<\/strong> and <strong>expect<\/strong> methods provided by Jasmine framework.<\/p>\n<p style=\"text-align: justify;\">Let&#8217;s create a sample HTML page which will load Jasmine Framework, our Javascript code and Test method to Test our code.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/JitendraZaa\/d76d262af41f8fc9bdba189161aed7a2.js\"><\/script><\/p>\n<p style=\"text-align: justify;\">Below is our files and folders structure<\/p>\n<figure id=\"attachment_6413\" aria-describedby=\"caption-attachment-6413\" style=\"width: 345px\" class=\"wp-caption aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-6413\" src=\"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Jasmine-Test-Framework-folder-structure.png?resize=345%2C325&#038;ssl=1\" alt=\"Jasmine Test Framework folder structure\" width=\"345\" height=\"325\" srcset=\"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Jasmine-Test-Framework-folder-structure.png?w=345&amp;ssl=1 345w, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Jasmine-Test-Framework-folder-structure.png?resize=300%2C283&amp;ssl=1 300w\" sizes=\"auto, (max-width: 345px) 100vw, 345px\" \/><figcaption id=\"caption-attachment-6413\" class=\"wp-caption-text\">Jasmine Test Framework folder structure<\/figcaption><\/figure>\n<p style=\"text-align: justify;\">Below is the output of our example. As all test passed, we don&#8217;t see any error<\/p>\n<figure id=\"attachment_6414\" aria-describedby=\"caption-attachment-6414\" style=\"width: 579px\" class=\"wp-caption aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-6414\" src=\"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Jasmine-Test-Framework-Output.png?resize=579%2C270&#038;ssl=1\" alt=\"Jasmine Test Framework Success Output\" width=\"579\" height=\"270\" srcset=\"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Jasmine-Test-Framework-Output.png?w=579&amp;ssl=1 579w, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Jasmine-Test-Framework-Output.png?resize=300%2C140&amp;ssl=1 300w\" sizes=\"auto, (max-width: 579px) 100vw, 579px\" \/><figcaption id=\"caption-attachment-6414\" class=\"wp-caption-text\">Jasmine Test Framework Success Output<\/figcaption><\/figure>\n<p style=\"text-align: justify;\">In case, if some method fails test execution, then it would show error report like below image<\/p>\n<figure id=\"attachment_6415\" aria-describedby=\"caption-attachment-6415\" style=\"width: 798px\" class=\"wp-caption aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-6415\" src=\"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Jasmine-Test-Framework-Error-Report.png?resize=798%2C373&#038;ssl=1\" alt=\"Jasmine Test Framework Error Report\" width=\"798\" height=\"373\" srcset=\"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Jasmine-Test-Framework-Error-Report.png?w=798&amp;ssl=1 798w, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Jasmine-Test-Framework-Error-Report.png?resize=300%2C140&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Jasmine-Test-Framework-Error-Report.png?resize=768%2C359&amp;ssl=1 768w\" sizes=\"auto, (max-width: 798px) 100vw, 798px\" \/><figcaption id=\"caption-attachment-6415\" class=\"wp-caption-text\">Jasmine Test Framework Error Report<\/figcaption><\/figure>\n<p style=\"text-align: justify;\"><strong>First 25 minutes<\/strong> of below video is basics of Jasmine Test Framework with same example as of this post.<\/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>Introduction to Jasmine framework and getting started with Behavior Driven Development (BDD) testing, along with Complete Source code and Video<\/p>\n","protected":false},"author":1,"featured_media":6416,"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":[19],"tags":[435,436,304,212],"class_list":["post-6411","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-webtech","tag-bdd","tag-jasmine","tag-testing","tag-video-tutorial"],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Jasmine-Testing-Frameowrk-Behavior-Drive-Development.png?fit=800%2C240&ssl=1","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":6419,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/introduction-to-lightning-test-services-with-jasmine\/","url_meta":{"origin":6411,"position":0},"title":"Introduction to Lightning Test Services with Jasmine","author":"Jitendra","date":"March 10, 2018","format":false,"excerpt":"Complete Source code and video of using Lightning Datatable Component and Jasmine in Salesforce","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Lightning Testing Service (LTS)","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Lightning-Testing-Service-LTS.png?fit=1200%2C433&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Lightning-Testing-Service-LTS.png?fit=1200%2C433&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Lightning-Testing-Service-LTS.png?fit=1200%2C433&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Lightning-Testing-Service-LTS.png?fit=1200%2C433&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Lightning-Testing-Service-LTS.png?fit=1200%2C433&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":6216,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/performing-load-testing-in-salesforce-using-selenium-and-testng\/","url_meta":{"origin":6411,"position":1},"title":"Performing Load Testing in Salesforce using Selenium and TestNG","author":"Jitendra","date":"August 28, 2017","format":false,"excerpt":"Parallel execution of browsers in Selenium with the help of TestNG and determining maximum operating capacity of custom code in Salesforce","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"Selenium Salesforce load Testing","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/08\/Selenium-Salesforce-load-Testing.jpg?fit=964%2C848&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/08\/Selenium-Salesforce-load-Testing.jpg?fit=964%2C848&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/08\/Selenium-Salesforce-load-Testing.jpg?fit=964%2C848&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/08\/Selenium-Salesforce-load-Testing.jpg?fit=964%2C848&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":4366,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/getting-started-with-selenium-and-salesforce-salesforce-automation-testing-video-tutorial-part-1\/","url_meta":{"origin":6411,"position":2},"title":"Selenium and Salesforce &#8211; Salesforce automation testing &#8211; Video tutorial &#8211; Part 1","author":"Jitendra","date":"March 28, 2015","format":false,"excerpt":"This is first post of multi-series article on using Selenium with Salesforce for Automation testing. Testing has always been integral part of any software development life cycle and Salesforce has already taken it to next level by making mandatory to have 75% of code coverage before any code deployment. These\u2026","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Sample Selenium Script","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/03\/Sample-Selenium-Script.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/03\/Sample-Selenium-Script.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/03\/Sample-Selenium-Script.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/03\/Sample-Selenium-Script.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":5351,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/test-setup-method-in-apex-test-class\/","url_meta":{"origin":6411,"position":3},"title":"Test Setup method in Apex","author":"Jitendra","date":"February 22, 2016","format":false,"excerpt":"How to use setup method in Apex test classes","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1241,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/step-by-step-salesforce-tutorial-creating-trigger-and-test-cases-6-of-6\/","url_meta":{"origin":6411,"position":4},"title":"Step by Step Salesforce Tutorial \u2013 Creating Trigger and Test cases \u2013 6 of 6","author":"Jitendra","date":"October 11, 2010","format":false,"excerpt":"Step by Step Salesforce Tutorial \u2013 Creating Trigger and test cases \u2013 6 of 6 tutorials series","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Creating Trigger in Salesforce using force.com IDE","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/10\/Creating-Trigger-in-Salesforce-using-force.com-IDE.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":3050,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/my-favorite-top-10-features-of-winter-13-release-salesforce\/","url_meta":{"origin":6411,"position":5},"title":"My Favorite Top 10 Features of Winter 13 release &#8211; Salesforce","author":"Jitendra","date":"August 24, 2012","format":false,"excerpt":"Dear Friends, I am very excited to write this article about the cool Winter 13 features which i have added in My List. There are lots of lots of new features added in this release and i have made the list of my top 10 favorite features. Yesterday Salesforce published\u2026","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Salesforce Winter 13 Release Notes","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/08\/Salesforce-Winter-13-Release-Notes-300x212.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/6411","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=6411"}],"version-history":[{"count":6,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/6411\/revisions"}],"predecessor-version":[{"id":6436,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/6411\/revisions\/6436"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media\/6416"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=6411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=6411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=6411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}