Contents
How to write unit tests on the Lightning Platform?
Write unit tests for Lightning components. Development on the Lightning Platform these days includes more than just Apex. It includes client-side Javascript in Lightning component controllers. Testing these involves a few specialized tools. This video introduces them. Lightning components are the building blocks of modern Salesforce applications.
How to test a lightning web component in Visual Studio?
To test a Lightning web component, we must first have a component to test. In Visual Studio Code, open the Command Palette by pressing Ctrl+Shift+P (Windows) or Cmd+Shift+P (macOS). Enter lightning web. Select SFDX: Create Lightning Web Component.
Which is the helper object in Lightning test?
One of the first things that happens in the test is a call to $T, the test helper object. In this case, you’re using $T to create an instance of the component c:egClientSideAction. $T is promise enabled, meaning the real work of your test is contained in the .then (component) method starting on line 72.
How to write jest test for lightning web component?
Jest tests for a Lightning web component should test the behavior of a single component in isolation, with minimal dependencies on external components or services. Go through the process again to create the unitTest test file This test will verify that a property is set and when added to the DOM will display the correct text.
Do you need to test JavaScript in Lightning?
Because Lightning components often contain client-side Javascript controllers, you need to test that logic. Apex is a proprietary language, so Salesforce provides built-in testing tools with the Lightning Platform. However, Javascript is an open language that Salesforce doesn’t control.
How to do unit testing in Salesforce Lightning?
In the Developer Console’s jasmineExampleTest.js tab, scroll down to the test suite starting on line 69. This test demonstrates invoking a client-side action and inspecting its behavior. One of the first things that happens in the test is a call to $T, the test helper object.