Unit Testing Lightning Components

Creating unit tests for code components helps in quickly figuring out issues with the component when a piece of code is redesigned or additional logic is added to enhance the functionality. Unit tests test a single function or object in isolation. Salesforce provides Apex unit tests for all the backend business logic written in Apex. For Lightning Components, Salesforce provides the Lightning Testing Service (LTS). The LTS is a set of wrappers for Jasmine and Mocha JavaScript testing frameworks. Jasmine is a popular framework to test JavaScript applications on, and uses a wide set of features, assisting in behavior-driven development (BDD), while Mocha is an emerging framework and requires additional frameworks (such as Chai, Sinon, or Cucumber) to work with it in order to provide a complete toolset to use to write unit tests. In this chapter, we will strictly cover only LTS, using Jasmine as the testing framework. The LTS (found at https://github.com/forcedotcom/LightningTestingServiceis open source, and hence it can be easily tailored to work with any testing framework. Once we know how this works with Jasmine, a similar approach can be applied to any testing framework that one chooses to adopt.

In this chapter, we will cover the following topics:

  • Introduction to Jasmine
  • LTS
  • Writing Jasmine test cases for two-way binding and server responses

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.222.185