Salesforce has introduced the Lighting Web Component as a lightweight framework. Lightning Web Component or LWC is the latest lightweight framework built on web standards. Since Salesforce is a member of the World Wide Web Consortium (W3C) and is committed to creating open web standards, it encourages the development of web standards on the Lightning platform. Our expert engineers have put together a quick guide to testing Lightning Web Components.
Using Lightning Web Components
LWC uses core web component standards to make sure that only the required and Salesforce-supported operations are performed in browsers. The code is native to the browsers, lightweight and is easy to use.
It provides users ease of access to custom elements, templates, shadow DOM, decorators and modules. LWC is different from the Aura because it will allow you to write web components, which most of the modern browsers support. An LWC framework will work as a translator between web components and browsers, so the latter can easily understand the components.
Testing Lightning Web Components
- Test a component in isolation
- Test a component’s public API properties, methods and events
- Test basic user interaction (clicks)
- Verify the DOM output of a component
- Verify that events fire when expected
Essentials of Testing with LWC
Like any other testing endeavor, there are steps that need to be completed before testing a Salesforce LWC. Let’s have a look at some of the important ones:
- Write one test case for different components and do not integrate multiple test cases into one
- Understand the length of the test case, which mainly depends on the component
- Before executing your test, the test case should describe the accomplishments
- Carefully document the expected results for different actions performed on the LWC
Tools for Testing LWC
The advantage of working with an LWC is that it has built-in Test-Driven Development (TDD), which makes writing tests simple. Below are some widely used tools for testing a Salesforce LWC.
Testing LWC with Jest
Testing Salesforce LWCs is still an unexplored horizon. You should initially write LWC tests in Jest and further in Jasmine and Mocha. If your recipe has some spices in it then definitely you will enjoy the test. To ensure comprehensive testing for LWC, get in touch with QASource experts today.