Salesforce Decode
Salesforcedecode
Back to questions
LWCIntermediatejestwiretesting

Test @wire adapters in Jest with emit and error simulation

Real World Scenario

LWC tests mock Apex imperatively but wire path untested causing production wire adapter regressions.

Expected Answer

• Import wire adapter emit from @salesforce/wire-service-jest-util • Emit mock data after element creation simulating wire success • Emit error object simulating wire failure path • Test reactive param change re-emit with new data • Assert DOM updates after emit not only property values • Mock getRecord getObjectInfo adapters consistently • Coverage gate includes wire success error and loading branches

Follow-Up Questions & Answers

Click to expand — each follow-up includes a direct, interview-ready answer

Direct answer: Import wire adapter emit from @salesforce/wire-service-jest-util Also consider: Emit mock data after element creation simulating wire success In practice: Emit error object simulating wire failure path Balance speed of delivery with maintainability.

Architect Perspective

Wire logic needs emit tests—imperative-only Jest suite misses half the data layer.