Capstone Reference Implementation: Testing and Deployment
By the end of this lesson, you'll be able to:
- Write Jest tests for the capstone's components
- Write Apex tests satisfying the platform's coverage requirement
- Deploy the feature and verify it against the Module 16 code review checklist
Prerequisites: "Capstone Reference Implementation: Components and UI"
Jest Tests for the Components
import { createElement } from 'lwc';
import CaseList from 'c/caseList';
describe('c-case-list', () => {
afterEach(() => {
while (document.body.firstChild) {
document.body.removeChild(document.body.firstChild);
}
});
it('dispatches caseselected with the row\'s accountId', () => {
const element = createElement('c-case-list', { is: CaseList });
element.cases = [{ id: '500xx', subject: 'Login issue', status: 'New', accountId: '001xx' }];
document.body.appendChild(element);
const handler = jest.fn();
element.addEventListener('caseselected', handler);
const datatable = element.shadowRoot.querySelector('lightning-datatable');
datatable.dispatchEvent(new CustomEvent('rowclick', {
detail: { row: { accountId: '001xx' } },
}));
expect(handler).toHaveBeenCalledTimes(1);
expect(handler.mock.calls[0][0].detail.accountId).toBe('001xx');
});
});
This directly follows Module 14's event-testing pattern — attaching the mock listener before triggering the interaction, then asserting on the dispatched event's detail.
Apex Tests for the Service/Controller
@isTest
private class CommandCenterServiceTest {
@isTest
static void testUpdateCaseStatusRejectsBlankStatus() {
Case testCase = new Case(Subject = 'Test', Status = 'New');
insert testCase;
Test.startTest();
try {
CommandCenterService.updateCaseStatus(testCase.Id, '');
System.assert(false, 'Expected an AuraHandledException for a blank status');
} catch (AuraHandledException e) {
System.assert(true);
}
Test.stopTest();
}
@isTest
static void testGetAccountSummaryThrowsForMissingAccount() {
Test.startTest();
try {
CommandCenterService.getAccountSummary(null);
System.assert(false, 'Expected an AuraHandledException for a missing account');
} catch (AuraHandledException e) {
System.assert(true);
}
Test.stopTest();
}
}
Following Module 14's Test.startTest()/stopTest() pattern, both the validation failure path and the not-found path are exercised directly against the Service layer — the same class the Controller merely delegates to.
Deployment Workflow
Module 2's SFDX workflow applies directly to shipping this feature: authenticate to the target org, deploy the new Apex classes and LWC bundles (sf project deploy start), then confirm the deployment passed the platform's Apex coverage requirement (Module 14) — the same requirement the tests above exist to satisfy.
Final Review Against the Checklist
Running Module 16's code review checklist against this capstone, as the closing step of the entire course:
- Separation of concerns — ✓ UI logic stays in components; business logic lives in
CommandCenterService. - Controller/Service/Selector layering — ✓ each layer has exactly one responsibility, with the Controller genuinely thin.
- Consistent error handling — ✓ every failure path surfaces through
AuraHandledExceptionandShowToastEvent, matching the pattern used throughout the course. - Appropriate configuration use — the capstone's requirements didn't call for admin-tunable values, so no Custom Metadata was introduced — correctly recognizing when configuration-driven design isn't needed is as much a sign of good judgment as using it when it is.
This is the same discipline applied consistently across all 20 modules — from Module 1's first "Hello Salesforce" component to this finished, tested, deployed feature.
Exercise
Write an Apex test asserting that CommandCenterService.updateCaseStatus successfully updates a Case's status when given a valid, non-blank value.
Show hint
Insert a test Case, call the method, then query and assert on the new status.
Exercise
Challenge: explain, as a comment, why the Jest test in this lesson tests the Apex tests' Service layer instead of the LWC component.
Show hint
Trick question — re-read which class the Apex test actually calls.
Capstone Reference Implementation: Testing and Deployment Quiz
My Notes
Log in to keep private notes on this lesson.
Questions about this lesson
No questions yet — be the first to ask.
Log in to ask a question about this lesson.
Summary
The final lesson closes the loop — real Jest and Apex tests, a deployment via the SFDX workflow from Module 2, and a last pass against the code review checklist that ties the entire course together.