Unit testing with Lightning Web Components
In this section, we are going to build a unit test for the Race Setup Lightning Web Component. This component has a number of dependencies that need to be mocked in order to build a successful unit test that covers the component’s HTML and JavaScript code. Here is a reminder of what the component looks like:
Figure 13.6: Race Setup LWC
When the user selects drivers and clicks Add Drivers, a confirmation toast message is shown:
Figure 13.7: Add Drivers confirmation message
The Race Setup component uses a lightning-table
child component defined in its HTML and methods from an Apex controller RaceSetupComponentController
class defined in its JavaScript controller. Lightning Web Components unit tests focus solely on the logic directly in the Race Setup component code (raceSetup.html
and raceSetup.js
) and have no other concerns; thus, we will focus on testing the following behaviors:
- When the component...